android - AsyncTask called a lot from many places -


i'm using simple asynctask download sourcecode of web page string. far works fine.

however, don't want same thing result string, want fill gui it, want parse it, want call more functions parameter. actually, have more 1 activity , more 1 class need download sourcecode of page.

of course, onpostexecute() has handle result of task, since called many places , many different reasons i'm @ loss.

what can do?

i don't want write 20 asynctasks same thing in doinbackground(...) different onpostexecute, nor want code 20 different classes/activity end in single onpostexecute, code complicated maintain.

any suggestion? thanks

i resolve use of interfaces. make async task right stuff in doinbackground , takes parameter know in onpostexecute , pass parameter , result down onpostexecute.

then make interface method handlesourcecodestring(string source); , implement 1 class every action want do. put classes in map in init function.

map<string, class> myactionmap = new hashmap<string,class>; myactionmap.put("parse-soruce", parsesource.class) //(where parsesource.class implements interface) 

and in postexecute like:

((myactioninterface)myactionmap.get(action).newinstance()).handlesourcecodestring(source); 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -