答案 0 :(得分:0)
我们无法直接为您提供代码,因为您的知识,我们建议您使用步骤或一些代码快照来指导您。
。实施firebase Job Dispatcher Firebase JobDispatcher
。成功添加库后,会创建一个扩展JobService的服务,如下所示。
import com.firebase.jobdispatcher.JobParameters;
import com.firebase.jobdispatcher.JobService;
public class MyJobService extends JobService {
@Override
public boolean onStartJob(JobParameters job) {
// Do some work here
//getLatestLocationAndUpdateOnserver()
//Don't miss to reschedule job
return false; // Answers the question:z "Is there still work going on?"
}
@Override
public boolean onStopJob(JobParameters job) {
return false; // Answers the question: "Should this job be retried?"
}
}
。最后,安排Job-like bellow
private void scheduleJob() {
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));
Bundle myExtrasBundle = new Bundle();
myExtrasBundle.putString("request_sender", "Data Want to add");
com.firebase.jobdispatcher.Job myJob = dispatcher.newJobBuilder()
.setService(MyJobService.class) // the JobService that will be called
.setTag("my-unique-tag")
.setTrigger(Trigger.executionWindow(600, 610)) //this will fire after 10minute
.setReplaceCurrent(true)// uniquely identifies the job
.setExtras(myExtrasBundle)
.build();
if (dispatcher != null) {
dispatcher.cancel("my-unique-tag");
}
dispatcher.mustSchedule(myJob);
}