android - Creating multiple asynctask for syncing files inside a service -


i have created service call main activity syncs files server. when service called call `new filelist().execute(); provides filelist uploading , downloading. on postexecute of asynctask call 2 further asynctasks uploading , downloading

for (int = 0; < files_server.size(); i++) {             filename=files_server.get(i);             new downloadfilefromurl().execute(file_url+files_server.get(i));             try {                 thread.sleep(100);             } catch (interruptedexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }           }  (int j = 0; j < files_phone.size(); j++) {             filepath=files_phone.get(j);             new uploadfiletoserver().execute();              try {                 thread.sleep(100);             } catch (interruptedexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }           } 

the code onstartcommand of service

new filelist().execute();     try {         thread.sleep(100);     } catch (interruptedexception e) {         // todo auto-generated catch block         e.printstacktrace();     } toast.length_short).show();        stopself();     return mstartmode; 

the code working fine new on android, couldn't find way not create many asynctask added delay not proper solution. me how , whether service option , whether stopping service ok?

try use intentservice instead of asynchtask. think should create 1 intentservice implementing task need in onhandleintent method. @ end of method should send obtained results registered broadcast receivers through sendbroadcast method. then, in dedicated broadcastreceiver should implement , register should catch messages sent intent service , handle them.

after have implemented such architecture should start intent service whenever need activity/fragment. using intent services don't have deal tasks queue and, yes, using delays balance queue not idea in humble opinion.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -