`JobIntentService`没有调用`OnHandleWork`。

huangapple go评论155阅读模式
英文:

JobIntentService not call OnHandleWork

问题

我有自定义的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" />

你有任何关于为什么它无法正常工作的想法吗?谢谢。

英文:

I've custom JobIntentService witn static method enqueueWork.

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

Also I've custom implementation of the FirebaseMessagingService. When I receive the push notification from FCM, I call the enqueueWork of my JobIntentService.

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

But method OnHandleWork not called on Android 8.0 and higher.
My manifest.xml.

&lt;service android:name=&quot;com.company.MyJobIntentService&quot;
			android:permission=&quot;android.permission.BIND_JOB_SERVICE&quot; /&gt;

Do you have any ideas why it work not correctly? Thank you.

答案1

得分: 1

没有错误。不幸的是,JobIntentService 在 Android 8.0 及更高版本上不会立即运行。

在作为 O 之前的服务运行时,将工作加入队列的操作通常会立即启动服务,而不管设备是否正在休眠或处于其他状态。当作为 Job 运行时,它将受到标准的 JobScheduler 策略的限制,对于设置了 setOverrideDeadline(long) 为 0 的 Job:在设备休眠时不会运行该作业,如果设备在内存压力较大且有大量需要运行的作业的情况下,它可能会比服务延迟更长时间。

在测试时,我创建了一个空项目,在调用时立即运行,但当我在一个真实的复杂项目中使用时,它会在调用后几分钟后运行。

英文:

Nothing incorrectly. Unfortunately, JobIntentService will not run immediately on Android 8.0 and higher.

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.

When testing,I new a empty project, it runs immediately when call, but when i use in a real complex project,it runs several minutes later after called.

huangapple
  • 本文由 发表于 2020年1月30日 18:34:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/59984013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定