0

我已经自定义JobIntentService 和静态方法enqueueWork

public static void enqueueWork(@NonNull Context context, @NonNull Intent intent) {        
            enqueueWork(context, MyJobIntentService.class, JOB_ID, intent);       
    }

我还自定义了 FirebaseMessagingService 的实现。当我收到来自 FCM 的推送通知时,我会调用JobIntentServiceenqueueWork

MyJobIntentService.enqueueWork(context, new Intent());

在 Android 8.0 及更高版本上未调用OnHandleWork 方法。我的manifest.xml

<service android:name="com.company.MyJobIntentService"
            android:permission="android.permission.BIND_JOB_SERVICE" />

你有什么想法为什么它不能正常工作?谢谢你。

4

1 回答 1

1

没有错。不幸的是,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.

测试时,我新建一个空项目,调用时立即运行,但在真正复杂的项目中使用时,调用后几分钟后运行。

于 2020-05-14T04:56:28.317 回答