Here's my 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
}
}
However, I got many crashes from the crashlytics which complained about 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)
Is there any reason to solve it?
I had tried to cancel it before enqueuing the new one as below:
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);
}
}
}
}
However, I got another issue:
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)
Do you guys have any suggestion?
P/s: I could not reproduce it on my devices, but I got it thousand times in CrashReport tool. Canceling work before enqueuing the new work did solve the 100 distinct jobs issue, but it raised another bug as above.