Instructions for migrating from CWAC Wakeful to JobIntentService?


#1

I’ve been using the WakefulIntentService, but since Google has informed me that I have to target API level 26 or higher as of 2 weeks ago, I’m trying to figure out how to move to JobIntentService.

The paragraph about it at GitHub wasn’t quite detailed enough. Are there more detailed, step-by-step instructions available somewhere?


#2

Not really, as I’m not sure what would be needed.

Here is a rough-cut conversion of the demo app’s service to a JobIntentService:

public class AppJobService extends JobIntentService {
  static final int JOB_ID = 1000;
  
  static void enqueueWork(Context context, Intent work) {
    enqueueWork(context, AppJobService.class, JOB_ID, work);
  }

  @Override
  protected void onHandleWork(Intent i) {
    Log.i("AppService", "I'm awake! I'm awake! (yawn)");
  }
}

(with bits of that code borrowed from the JobIntentService JavaDocs)

Then, instead of WakefulIntentService.sendWakefulWork(context, AppService.class);, you would use AppJobService.enqueueWork(context, new Intent(context, AppJobService.class));.

If there is something more that you need, let me know!


#3

Thanks! That gave me the boost I needed to figure the rest out. :smile: