自定义JobIntentService onHandleWork未调用 [英] Custom JobIntentService onHandleWork not called

查看:643
本文介绍了自定义JobIntentService onHandleWork未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近正在更新一个正在使用的应用程序,该应用程序使用JobIntentService而不是常规的IntentService来处理来自推送的通知,因为这似乎是在棒棒糖之前和之后的设备上处理此通知的正确方法.我正在加入这样的工作:

enqueueWork(context, MyJobServiceExtension.class, JOB_ID, work);

这是清单声明:

<service android:name="com.example.MyJobServiceExtension"
            android:permission="android.permission.BIND_JOB_SERVICE"
            android:exported="true"
            tools:node="replace">

我从没在onHandleWork中看到任何回调,也没有在logcat中看到任何错误日志.有没有人成功整合了这一功能,可以提供帮助?

更新1

我在API级别21的设备上对此进行了测试,并且可以正常工作..但是在我的Android Oreo Pixel XL设备上似乎没有被调用..为什么有任何线索?

更新2

我似乎也看到了IntentService的onCreate被调用,但是没有其他的生命周期方法(包括onHandleWork).有人遇到过吗?

解决方案

从IntentService升级到JobIntentService后,我遇到了同样的问题.确保从旧的实现中删除此方法:

@Override
public IBinder onBind(Intent intent) {
    return null;
}

对我来说,这解决了问题,现在它可以在Oreo之前和之后使用.

I recently was updating an app that I work on to handle notifications from push using a JobIntentService instead of a regular IntentService because it seems like the correct way to handle this on pre-Lollipop devices as well as post. I am enqueueing work as such:

enqueueWork(context, MyJobServiceExtension.class, JOB_ID, work);

This is the manifest declaration:

<service android:name="com.example.MyJobServiceExtension"
            android:permission="android.permission.BIND_JOB_SERVICE"
            android:exported="true"
            tools:node="replace">

I never see any callbacks in onHandleWork or any error logs in my logcat. Has anyone successfully integrated this that could help?

Update 1

I tested this on an API level 21 device and it worked.. but it doesn't seem to be getting called on my Android Oreo Pixel XL device.. Any clues as to why?

Update 2

Also I seem to be seeing the IntentService's onCreate be called, but none of the other lifecycle methods (including onHandleWork). Has anyone encountered this either?

解决方案

I had the same issue after upgrading from IntentService to JobIntentService. Make sure you remove this method from your old implementation:

@Override
public IBinder onBind(Intent intent) {
    return null;
}

For me this solved the problem, and now it works both on pre- and post-Oreo.

这篇关于自定义JobIntentService onHandleWork未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆