0

my question is very easy but i've been struggling with this for a long!

I have a Bound Service that call the onBound() method:

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

Unlikley, it's impossible to use that implementation with JobIntentService becouse it will throw a JobServiceContext: Time-Out with binding service

Of course, removing that overriding method is not the solution since i can't remove it...

This is my JobIntenteservice

JobBoot.java

public class JobBoot extends JobIntentService {

public static final int JOB_ID = 0x01;

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

@Override
protected void onHandleWork(@NonNull Intent intent) {
    // your code
}}

What can i do to fix this issue??

Thanks

androidexpert35
  • 319
  • 1
  • 10

1 Answers1

0

In class JobBoot's static method enqueueWork, it should use JobBoot instead of BackgroundService.

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

and in JobBoot's onHandleWork

   protected void onHandleWork(@NotNull Intent intent) {

     // 
     Intent intent = new Intent(this, BackgroundService.class)
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
         startForegroundService(intent)
     } else {
         startService(intent)
     }
}
fangzhzh
  • 2,172
  • 21
  • 25