android - Job Service is destroying after some -
i have implemented jobservice in application don't know reasons stopping suddenly, , changing job time dynamically based on req.
here code
i calling startservice(context context) when interval changes
public class gcmlocationservice extends jobservice { @override public boolean onstartjob(jobparameters job) { sendlocationtoserver(); return false; } @override public boolean onstopjob(jobparameters job) { return false; } public static void startservice(context context) { // create new dispatcher using google play driver. integer locationinterval = integer.parseint(sessionmanager.getinstance(context).getpreflocationinterval()); int min = 10; int max = 10; if (locationinterval > 2) { max = locationinterval * 60; min = (locationinterval - 1) * 60; } clog.e("gcmintentservice taskservice", "111 locationinterval------->" + sessionmanager.getinstance(context).getpreflocationinterval()); firebasejobdispatcher dispatcher = new firebasejobdispatcher(new googleplaydriver(context)); job job = dispatcher.newjobbuilder() .setservice(gcmlocationservice.class) // uniquely identifies job .settag(myapplication.gcm_location_repeat_tag) // one-off job .setrecurring(true) // don't persist past device reboot .setlifetime(lifetime.until_next_boot) // start between 0 , 60 seconds .settrigger(trigger.executionwindow(min, max)) // don't overwrite existing job same tag .setreplacecurrent(true) // retry exponential backoff .setretrystrategy(retrystrategy.default_exponential) // constraints need satisfied job run .setconstraints() .build(); dispatcher.newretrystrategy(retrystrategy.retry_policy_linear, 60, 301); dispatcher.schedule(job); clog.d("location-- s>", "222 schedule job"); }
Comments
Post a Comment