Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecurityException: Caller no longer running

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)
like image 631
Santhosh Avatar asked May 14 '18 15:05

Santhosh


1 Answers

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.

like image 66
Bipin Avatar answered Nov 09 '22 01:11

Bipin