我有一个场景,即使应用程序关闭,我也必须听取XMPP连接状态。现在我正在使用Firebase网络调度程序,因为GCM网络管理器已被弃用,它仅在应用程序处于前台/后台时才有效。只要应用程序关闭,它就会停止。有人可以提出建议吗?以下是我的代码段。
Driver driver = new GooglePlayDriver(getApplicationContext());
FirebaseJobDispatcher firebaseJobDispatcher = new FirebaseJobDispatcher(driver);
Job constraintReminderJob = firebaseJobDispatcher.newJobBuilder()
.setService(FirebaseService.class)
.setTag("Notify Tag")
.setLifetime(Lifetime.UNTIL_NEXT_BOOT)
.build();
firebaseJobDispatcher.schedule(constraintReminderJob);
答案 0 :(得分:0)
Driver driver = new GooglePlayDriver(context);
FirebaseJobDispatcher firebaseJobDispatcher = new FirebaseJobDispatcher(driver);
Job constraintReminderJob = firebaseJobDispatcher.newJobBuilder()
.setService(ReminderService.class)
.setTag(REMINDER_JOB_TAG)
.setConstraints(Constraint.DEVICE_CHARGING)
.setLifetime(Lifetime.FOREVER)
.setRecurring(true)
.setTrigger(Trigger.executionWindow(
REMINDER_INTERVAL_SECONDS,
REMINDER_INTERVAL_SECONDS + SYNC_FLEXTIME_SECONDS
))
.setReplaceCurrent(true)
.build();
firebaseJobDispatcher.schedule(constraintReminderJob);