SecurityException: Caller no longer running

Santhosh picture Santhosh · May 14, 2018 · Viewed 7k times · Source

I am facing below issue in Android O and above when trying to run my JobIntentService, I am having a tough time to reproduce the issue :

Caused by java.lang.SecurityException: Caller no longer running, last stopped +206ms because: timed out while starting
   at android.os.Parcel.readException(Parcel.java:1942)
   at android.os.Parcel.readException(Parcel.java:1888)
   at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
   at android.app.job.JobParameters.dequeueWork(JobParameters.java:196)
   at android.support.v4.app.JobIntentService$JobServiceEngineImpl.dequeueWork(JobIntentService.java:314)
   at android.support.v4.app.JobIntentService.dequeueWork(JobIntentService.java:639)
   at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:389)
   at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
   at android.os.AsyncTask$2.call(AsyncTask.java:333)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
   at java.lang.Thread.run(Thread.java:764)

Answer

Bipin picture Bipin · Jun 7, 2018

Let your jobIntentService extend MyJobIntentService

This will handle multiple dequeueWork call going to remoteProcess, even if the remoteProcess throws security exception for poping already removed work off the stack

package android.support.v4.app;

import timber.log.Timber;

public abstract class MyJobIntentService extends JobIntentService {   

    @Override

    GenericWorkItem dequeueWork() { 
        try {
            return super.dequeueWork();
        } catch (SecurityException ignored) {
            Timber.e(ignored);
        }    
        return null;
    }
}

Note: Important to create the package "android.support.v4.app" As GenericWorkItem class is inside this package to get access.