java - JobIntentService 不调用 OnHandleWork
问题描述
我已经自定义JobIntentService 和静态方法enqueueWork。
public static void enqueueWork(@NonNull Context context, @NonNull Intent intent) {
enqueueWork(context, MyJobIntentService.class, JOB_ID, intent);
}
我还自定义了 FirebaseMessagingService 的实现。当我收到来自 FCM 的推送通知时,我会调用JobIntentService的enqueueWork。
MyJobIntentService.enqueueWork(context, new Intent());
但在 Android 8.0 及更高版本上未调用OnHandleWork 方法。我的manifest.xml。
<service android:name="com.company.MyJobIntentService"
android:permission="android.permission.BIND_JOB_SERVICE" />
你有什么想法为什么它不能正常工作?谢谢你。
解决方案
没有错。不幸的是,JobIntentService 不会立即在 Android 8.0 及更高版本上运行。
When running as a pre-O service, the act of enqueueing work will generally start the service immediately, regardless of whether the device is dozing or in other conditions. When running as a Job, it will be subject to standard JobScheduler policies for a Job with a setOverrideDeadline(long) of 0: the job will not run while the device is dozing, it may get delayed more than a service if the device is under strong memory pressure with lots of demand to run jobs.
测试时,我新建一个空项目,调用时立即运行,但在真正复杂的项目中使用时,调用后几分钟后运行。
推荐阅读
- python - 我想知道我对使用 keras 实现 lstm 层是否正确
- mongodb - MongoDB 找不到包含相同日期的两个不同字段的文档
- node.js - 如何使用 mongoose 控制器路由将两个 mongodb 集合连接在一起?
- android - 如何防止特定风味的单元测试以另一种风味编译?
- sql - 如何优化 Postgres 中存储过程的性能?
- ruby-on-rails - 我可以使用类似于 String#constantize 的东西来初始化 Hyperstack::Component 吗?
- javascript - 使用单个循环仅添加数组的不同元素
- android - 如何从 URL 链接下载音频文件?
- swift - 如何使表格视图单元格中的按钮工作
- javascript - 通过 /{id} json-server 删除 div