Since I started to use JobIntentService, which replaced IntentService post Android-Oreo, I started to have crashes in my console. It is not crash in my code, but in androix library (and also it can not reproduce them on my device, because it only happens for around 1 in ~1000 users).
This is console:
java.lang.RuntimeException:
at android.os.AsyncTask$4.done (AsyncTask.java:415)
at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383)
at java.util.concurrent.FutureTask.setException (FutureTask.java:252)
at java.util.concurrent.FutureTask.run (FutureTask.java:271)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:923)
Caused by: java.lang.IllegalArgumentException:
at android.app.job.JobParameters.completeWork (JobParameters.java:312)
at androidx.core.app.JobIntentService$JobServiceEngineImpl$WrapperWorkItem.complete (JobIntentService.java:267)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:393)
at androidx.core.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:382)
at android.os.AsyncTask$3.call (AsyncTask.java:394)
at java.util.concurrent.FutureTask.run (FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:923)
I checked out source codes and it crashes on line Given work is not active in JobParameters class, see code:
public void completeWork(@NonNull JobWorkItem work) {
try {
if (!getCallback().completeWork(getJobId(), work.getWorkId())) {
throw new IllegalArgumentException("Given work is not active: " + work);
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
What does it mean? How can I prevent this from happening? I am not aware of doing anything wrong...It is a standard JobIntentService. (and yes, I am using UNIQUE job ID). This is simplified code:
public class UpdateService extends JobIntentService {
public static final int JOB_ID = 340957; // this ID is unique in my whole app
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, UpdateService.class, JOB_ID, work);
}
@Override
public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
protected void onHandleWork(Intent intent) {
// some work here
}
}
What am I doing wrong?