Call multiple services in background in android -


i have call multiple services in background project in android app. in each services have call separate web service , data , process local sqlite database. able call each service separately , can manipulate result local database. not able call services in sequence. code below:

@override     public void onstart(intent intent, int startid) {         toast.maketext(this, "my service started", toast.length_long).show();         timer timer = new timer();          final synctableusers syncuserobj = new synctableusers(localservice.this);         final synctablevehicles syncvehicleobj = new synctablevehicles(this);         final synctablelicenses synclicenseobj = new synctablelicenses(this);         final synctabletags synctagobj = new synctabletags(this);         final synctabletagmappings synctagmapobj = new synctabletagmappings(this);         final synctableaddresses syncaddressobj = new synctableaddresses(this);         final synctabledispatches syncdispatchobj = new synctabledispatches(this);         final synceditcompany synccompanyobj = new synceditcompany(localservice.this);         final synceditvehicle synceditvehicleobj = new synceditvehicle(localservice.this);         final syncedituser syncedituserobj = new syncedituser(this);         final syncvehiclelog vlogobj = new syncvehiclelog(localservice.this);         timertask timertask = new timertask() {              @override             public void run() {                         syncuserobj.syncuserdata();                         syncvehicleobj.syncvehicledata();                         synclicenseobj.synclicensesdata();                         synctagobj.synctagdata();                         synctagmapobj.synctagmappingdata();                         syncaddressobj.syncaddressdata();                         syncdispatchobj.syncdispatchdata();                         synccompanyobj.synccompanydata();                         synceditvehicleobj.syncvehicledata();                         syncedituserobj.syncuserdata();                         log.i("tag", "logid after insert values ");                 }             }         };         timer.scheduleatfixedrate(timertask, 10000, 180000);  call after every                                                              3 minute         super.onstart(intent, startid); 

syncuserdata method, call web service.

i recommend go asynctask solution. easy , straightforward way of running requests or other background tasks , calling web services using devices having latest os virsion must need use asynctask.

it's easy implement e.g. onprogressupdate if need show progress bar of sort while running requests.

private class yourtask extends asynctask<url, integer, long> {  protected long doinbackground(url... urls) {     //call methods here          //publish yor progress here..         publishprogress((int) ((i / (float) count) * 100));  }   protected void onprogressupdate(integer... progress) {      setprogresspercent(progress[0]);  }   protected void onpostexecute(long result) {     //action after execution success or not  } } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -