asynchronous - How to wait for an async method to be completed in a background tast -
implementing backgroung task fetch checksum on remote server , update live tile accordingly, i've bumped timing issue.
here's code :
matchlistimpl.istherenewresults(); newslistimpl.istherenewnews(); raisetoast(); updatetile();
it's rather simple. first 2 calls refering async function download 2 files "*.cksum" using webconnector. last 2 calls update tile , raise notification depending on content of downloaded files.
the problem later function executed before 2 files downloaded, async method not being completed. , of course, whole logic of thing void.
my question : there way "pause" execution of task wait async method on ?
as absolutely unelegant, second question : there not better way of doing ?
thanks yours answers :)
you can pass current class async task , in onpostexecute method of async class call raisetoast() , updatetile() example: assuming in raisetoast() using files downloaded in matchlistimpl async task , can pass current class raisetoast() in ther async task class , in it's constructor.
class matchlistimpl extends asynctask{ classcontainingraisetoast myclass; //contructor: matchlistimpl(classcontainingraisetoast myclass){ this.myclass = myclass; } ... @override //this method executed after finishing asynctask job protected void onpostexecute(string result) { super.onpostexecute(result); // raisetoast() must declared public in myclass myclass.raisetoast(); } }
so don't call raisetoast() in myclass itself. , call in asynctast class istead!
Comments
Post a Comment