26

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)
SAYE
  • 1,247
  • 2
  • 20
  • 47
Santhosh
  • 1,867
  • 2
  • 16
  • 23

1 Answers1

5

Let your jobIntentService extend MyJobIntentService

This will handle multiple dequeueWork call going to remoteProcess, even if the remoteProcess throws a security exception for popping 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 a package "android.support.v4.app" Since the GenericWorkItem class is inside this package to gain access.

Hamza Hmem
  • 502
  • 5
  • 11
Bipin
  • 334
  • 2
  • 6
  • 5
    `GenericWorkItem` is a protected class. I can't access it whille extending the JobIntentService. – dasfima Aug 04 '18 at 12:15
  • 3
    Same issue. This is not a complete answer. – StarWind0 Aug 06 '18 at 16:08
  • i assume that you have not created a package name try creating a package ---android.support.v4.app--- then add the file inside that... you will be able to access GenericWorkItem. – Bipin Aug 06 '18 at 19:04
  • 1
    Yeah I see now that you are saying to create a package that matches the support libraries path in your app, allowing you to access these functions. Though that means you have to test this code every time you version bump the support library. Not really a solution I would do unless I had absolutely no choice. – StarWind0 Aug 14 '18 at 20:09
  • 1
    according to comments on [Issue Tracker](https://issuetracker.google.com/issues/63622293), e.g. #120 & #121, that may cause another problem - `onHandleWork` not getting called... – snachmsm Apr 23 '19 at 11:35