我正在测试一个接收Firebase云数据消息并在Firebase职位服务中处理它们的应用程序。在Firebasemessagingservice中接收消息会立即发生并且没有问题,但是Firebase的工作服务有时会延迟延迟(5-10分钟),有时根本没有开始。调度程序(myjob)方法始终给出结果schedue_result_success。这是工作调度功能:
// For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
Bundle bundle = new Bundle();
bundle.putInt(WatchDogService.REQUEST_ID, request.ordinal());
bundle.putString(REQUEST_PARAM, parameter);
FirebaseJobDispatcher dispatcher =
new FirebaseJobDispatcher(new GooglePlayDriver(this));
Job myJob = dispatcher.newJobBuilder()
.setService(LongJobService.class)
.setTag("ua.ers.LongJobService")
.setTrigger(Trigger.NOW)
.setReplaceCurrent(true)
.setExtras(bundle)
.build();
int result = dispatcher.schedule(myJob);
Log.d(TAG, "Schedule result: " + result);
这是一个firebase职位服务类:
public class LongJobService extends JobService {
private static final String TAG = "LongJobService";
@Override
public boolean onStartJob(final JobParameters jobParameters) {
Log.d(TAG, "LongJobService started");
return true;
}
@Override
public boolean onStopJob(JobParameters jobParameters) {
Log.d(TAG, "LongJobService stopped");
return false;
}
}
请告诉我,问题的原因是什么?
根据文档,这只是通常的行为
鼓励调度程序后端使用窗口固定值作为应运行作业的信号,但这不是强制性行为。
,但是要获得更好的执行尝试
Trigger.executionWindow(0, 0)
而不是
Trigger.NOW
所以看起来像
Job myJob = dispatcher.newJobBuilder()
.setService(Service.class)
.setRecurring(true) // if task is periodic, else pass "false"
.setTrigger(Trigger.executionWindow(0, 0))
.setTag("tag")
.build();