【问题标题】:JobIntentService not call OnHandleWorkJobIntentService 不调用 OnHandleWork
【发布时间】:2020-05-15 22:47:54
【问题描述】:

我已经自定义 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());

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

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

您知道为什么它不能正常工作吗?谢谢。

【问题讨论】:

    标签: java android jobintentservice


    【解决方案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.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2020-05-29
      • 1970-01-01
      • 2021-06-01
      相关资源
      最近更新 更多