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
Post a Comment