IllegalArgumentException with JobIntentService in Background

360 views Asked by At

I am using JobIntentService to detect activities from the Google Activity Transition API.

After an Update with Target SDK 30 (Android 11) I am receiving a lot of crashes in Crashlytics across all Android plattforms. They happen 99% in the background, and I am not able to reproduce it by myself.

Fatal Exception: java.lang.RuntimeException
An error occurred while executing doInBackground()
android.os.AsyncTask$4.done (AsyncTask.java:415)
java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383)
java.util.concurrent.FutureTask.setException (FutureTask.java:252)
java.util.concurrent.FutureTask.run (FutureTask.java:271)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
java.lang.Thread.run (Thread.java:923)
Caused by java.lang.IllegalArgumentException
Given work is not active: JobWorkItem{id=1 intent=Intent { flg=0x10 cmp=com.myapp/com.myapp.activity.ActivityRecognitionWorkReceiver (has extras) } dcount=15}
android.app.job.JobParameters.completeWork (JobParameters.java:312)
androidx.core.app.JobIntentService$JobServiceEngineImpl$WrapperWorkItem.complete (JobIntentService.java:272)
androidx.core.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:398)
androidx.core.app.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:387)
android.os.AsyncTask$3.call (AsyncTask.java:394)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
java.lang.Thread.run (Thread.java:923)

For receiving the events I am using a Broadcast receiver, and from that I enqueue a jobservice with an unique job-ID

 fun enqueueWork(context: Context, intent: Intent) {
        JobIntentService.enqueueWork(
            context,
            ActivityTransitionJobService::class.java,
            UNIQUE_JOB_ID,
            intent
            )
        }

I am using the latest work runtime library (By today 20.12.2021)

implementation"androidx.work:work-runtime-ktx:2.7.1"

The questions here are:

  • how can I identify & hopefully fix that issue
  • Are there any other recommended solutions for Google Activity Transition API in the Background? The official sample is still using IntentService, but this is deprecated with replacement of JobIntentService, which is also now deprecated.

Any help is really appreciated

0

There are 0 answers