我正在测试一个接收 Firebase 云数据消息并在 Firebase 作业服务中处理它们的应用程序。在 FirebaseMessagingService 中接收消息会立即发生并且没有问题,但 Firebase 作业服务有时会延迟很长时间(5-10 分钟),有时根本不会启动。dispatcher.schedule (myJob) 方法总是给出结果 SCHEDULE_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;
}
}
请告诉我,问题的原因可能是什么?