0

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.

Kingfisher Phuoc
  • 8,052
  • 9
  • 46
  • 86
  • 2
    Any help for this? I am getting the same issue. – Sujeet Kumar Jun 14 '19 at 08:52
  • I'm facing the same issue with my implementation. All finished jobs are somehow created over again if I start a new job. I'm on 2.0.1. It's supposedly fixed in some earlier alpha version as mentioned in https://stackoverflow.com/questions/52286698/alpha-08-apps-may-not-schedule-more-than-100-distinct-jobs but I don't think so. – ArunL Jul 15 '19 at 12:21
  • Did you find a solution to this? – Jalpesh Jan 08 '20 at 05:12

0 Answers0