android SecurityException:呼叫方不再运行

uqdfh47h  于 2023-05-21  发布在  Android
关注(0)|答案(1)|浏览(250)

我在AndroidO及以上版本中尝试运行JobIntentService时遇到以下问题,我很坚韧重现该问题:

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)
m1m5dgzv

m1m5dgzv1#

让您的jobIntentService扩展MyJobIntentService
这将处理去往remoteProcess的多个dequeueWork调用,即使remoteProcess抛出一个安全异常,将已经移除的工作弹出堆栈

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;
    }
}

注意:创建一个包“android.support.v4.app“是很重要的,因为GenericWorkItem类在这个包中以获得访问权。

相关问题