androidandroid-8.0-oreojobservicejobintentservice

Custom JobIntentService onHandleWork not called


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?


Solution

  • 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.