android - 应用程序不能使用 JobIntentService 安排超过 100 个不同的作业
问题描述
这是我的JobIntentService
public class NotifierService extends JobIntentService {
public static void enqueueWork(Context context, Intent work) {
enqueueWork(context, NotifierService.class, JOB_ID, work);
}
protected void onHandleWork(Intent intent) {
//simple if/else check
}
}
但是,我从抱怨的 crashlytics 中遇到了很多崩溃100 distinct jobs
:
Caused by java.lang.IllegalStateException: Apps may not schedule more than 100 distinct jobs
at android.os.Parcel.readException(Parcel.java:1951)
at android.os.Parcel.readException(Parcel.java:1889)
at android.app.job.IJobScheduler$Stub$Proxy.enqueue(IJobScheduler.java:211)
有什么理由解决吗?
在将新的排队之前,我曾尝试取消它,如下所示:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
JobScheduler scheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (scheduler != null) {
for (JobInfo jobInfo : scheduler.getAllPendingJobs()) {
if (jobInfo.getId() == JOB_ID) {
scheduler.cancel(JOB_ID);
}
}
}
}
但是,我遇到了另一个问题:
Caused by java.lang.IllegalArgumentException: Given work is not active: JobWorkItem{id=1 intent=Intent { cmp=com.my.test.package/.notifier.NotifierService } dcount=1}
at android.app.job.JobParameters.completeWork(JobParameters.java:221)
你们有什么建议吗?
P/s:我无法在我的设备上重现它,但我在 CrashReport 工具中得到了数千次。在加入新工作之前取消工作确实解决了 100 个不同的工作问题,但它引发了如上所述的另一个错误。
解决方案
推荐阅读
- python - 在这种情况下,如何在使用 dask 时添加元信息?
- reactjs - TypeError:无法读取 null、webpack 的属性“哈希”
- javascript - 为什么 dispatch() 正在添加附加属性“未定义”
- python - 将一行中的 for-loop 转录为阶梯式 for-loop
- android - BottomSheetDialog 似乎在 MaterialDesign Library v1.4.0 中有一个错误
- c++ - 如何从类方法对 C++ 中的类进行操作?
- polymorphism - 如何在 Graphql-Java 中处理运行时多态性
- jquery - 页面加载时的 jQuery 下拉菜单
- javascript - 如何附加一个包含内部内容的子 div
- spring-boot - 为什么我们在开发 REST API 时使用 @RequestHeader 注解?