I need to handle intents posted via AlarmManager both while my app runs and at boot time. I've written a subclass of JobIntentService to handle the intents but it's not working as expected: onHandleWork is not called.
My implementation worked when the handler was an IntentService, except at boot time due to restrictions on background services. I'm therefore attempting to use a JobIntentService instead.
public class MyJobIntentService extends JobIntentService
{
public int onStartCommand(@Nullable Intent intent, int flags, int startId)
{
// This gets called with the intent given to AlarmManager
return super.onStartCommand(intent, flags, startId);
}
public static void enqueueWork(Context context, Intent work)
{
// Not called
enqueueWork(context, NotificationService.class, JOB_ID, work);
}
public void onHandleWork(@NonNull Intent intent)
{
// Not called
...
}
// No other methods overridden
}
onStartCommand is called. The documentation says that this method:
Processes start commands when running as a pre-O service, enqueueing them to be later dispatched in onHandleWork(Intent).
I don't know what 'later' is supposed to mean here but onHandleWork is not in fact called, even though onStartCommand has been called with the expected intent.
I've read answers to similar questions and ensured that I don't override other methods. I've also created a manifest entry for the service which I assume is correct - or onStartCommand wouldn't be called.
This is how I create the PendingIntent used with AlarmManager:
Intent myIntent = new Intent( myContext, MyJobIntentService.class);
...
PendingIntent pendingIntent = PendingIntent.getService( mContext, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
myAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
Any ideas on what I'm missing?