0

I have a skeleton class of JobIntentService

public class BackgroundRequestService extends JobIntentService {
/**
 * Unique job ID for this service.
 */
static final int JOB_ID = 1234;

public static void enqueueWork(Context context, Intent work) {
    BackgroundRequestService.enqueueWork(context, BackgroundRequestService.class, JOB_ID, work);
}


@Override
protected void onHandleWork(@NonNull Intent intent) {

    if (intent.getExtras() != null){
        String x = ";";
    }
}

}

I have included the Service in the manifest

 <service android:name=".BackgroundRequestService"
        android:enabled="true"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="false" />

And calling the proper enqueue method

Intent intent = new Intent();
        intent.putExtra("hardware", hardware);
        BackgroundRequestService.enqueueWork(context, intent);

But the onHandleWork is never getting called. i have looked at all the pages about setting the services correctly and making sure onBind isn't overridden, but this still isn't working, wondering if another set of eyes would spot something ive missed. Thank you

Brandon
  • 1,158
  • 3
  • 12
  • 22
  • 1
    Hi Brandon, I am having the same problem (but its random - most of the times onHandleWork is called, but sometimes as if whole app was blocked and it isnt). It is totally random, have you found the root cause? Thanks – qkx Jun 18 '21 at 10:30

2 Answers2

0

Try to start service this way:

 ComponentName comp = new ComponentName(context.getPackageName(), BackgroundRequestService.class.getName());
 BackgroundRequestService.enqueueWork(context, (getIntent().setComponent(comp)));
  • I've found the problem with my specific issue, thank you though and i'll give it a try and see if this works when i fix up the Serialization issue – Brandon Dec 13 '18 at 03:57
0

Found the issue through some proper looking into the Logcat

Turns out the "hardware" that i was putting into my Intent was missing a field to be Serialized.

This caused this message to appear in the Logcat

I/UDP: no longer listening for UDP broadcasts cause of error Parcelable encountered IOException writing serializable object (name = Project.Hardware)

After fixing this Serialization issue i was able to call the onHandleWork() method.

Brandon
  • 1,158
  • 3
  • 12
  • 22