自从我开始使用 JobIntentService,它取代了 Android-Oreo 之后的 IntentService,我的控制台开始出现崩溃。它不是在我的代码中崩溃,而是在 android 库中(而且它也无法在我的设备上重现它们,因为它只发生在大约 1000 个用户中)。
这是控制台:
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)
我检查了源代码,它Given work is not active
在 JobParameters 类中在线崩溃,请参阅代码:
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();
}
}
这是什么意思?我怎样才能防止这种情况发生?我不知道做错了什么......这是一个标准的 JobIntentService。(是的,我使用的是唯一的工作 ID)。这是简化的代码:
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
}
}
我究竟做错了什么?