android - How to perform background recurring job using firebase job dispatcher -


i have configured job following :

firebasejobdispatcher dispatcher = new firebasejobdispatcher(new googleplaydriver(this));     job myjob = dispatcher.newjobbuilder()             .setservice(infojobservice.class)             .setrecurring(true)             .settrigger(trigger.executionwindow(0, 10))             .setlifetime(lifetime.forever)             .settag("data")             .setreplacecurrent(true)             .setconstraints(constraint.on_any_network)             .build();     dispatcher.mustschedule(myjob); 

in jobservice class have modified onstart , onstop method following:

 @override public boolean onstartjob(jobparameters job) {     new thread(new runnable() {         @override         public void run() {             uploaddattofirebase();         }     }).start();     return true; } @override public boolean onstopjob(jobparameters job) {     return true; } 

but job dispatcher only worked once , not recurring.my question similar this question no solution given there, had ask again.

i don't know if solutions ideal every case , worked me. jobservice:

@override public boolean onstartjob(final jobparameters job) {     new thread(new runnable() {         @override         public void run() {             uploaddattofirebase(job);         }     }).start();      return true; }    @override public boolean onstopjob(jobparameters job) {     return false; }  private void uploaddattofirebase(final jobparameters parameters) {     try{         dosomething();         thread.sleep(2000);     }catch (interruptedexception e) {         e.printstacktrace();     } {         jobfinished(parameters, true);     } } 

and in activity:

 firebasejobdispatcher dispatcher = new firebasejobdispatcher(new googleplaydriver(this));      job myjob = dispatcher.newjobbuilder()             .setservice(infojobservice.class)             .settag("infojobservice")             .setrecurring(true)             .settrigger(trigger.executionwindow(30, 60))             .setlifetime(lifetime.forever)             .setreplacecurrent(false)             .setconstraints(constraint.on_any_network, constraint.device_charging)             .setretrystrategy(retrystrategy.default_linear)             .build();      dispatcher.mustschedule(myjob); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -