2

I have a particular crash happening on Samsung devices for the most part with Android version 10. I have a JobScheduler which schedules jobs and has them in a queue for later execution.

ComponentName jobService = new ComponentName(getApplicationContext(), HeartBeatJobService.class);
JobInfo.Builder builder = new JobInfo.Builder(HeartBeatJobService.JobID, jobService);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        {
            builder.setPeriodic(JobInfo.getMinPeriodMillis(), JobInfo.getMinFlexMillis());
        }
        else
        {
            long REFRESH_INTERVAL = 15 * 60 * 1000; // every 15 minutes
            builder.setPeriodic(REFRESH_INTERVAL);
        }
        builder.setPersisted(true);

        try
        {
            List<JobInfo> jobs = js.getAllPendingJobs();
            js.schedule(builder.build());
        }
        catch (Exception e)
        {
            RecordException(e2);  
        }

Sometimes, there are more than 100 jobs queued as I have a piece of code which reschedules a job if something went wrong. So the app tries to resubmit this job multiple times and I assume this is done for upto 100 times which causes the crash as follows:-

Non-fatal Exception: java.lang.IllegalStateException: Apps may not schedule more than 100 distinct jobs
       at android.os.Parcel.createException(Parcel.java:2096)
       at android.os.Parcel.readException(Parcel.java:2056)
       at android.os.Parcel.readException(Parcel.java:2004)
       at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:324)
       at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:43)
       at package.onCreate(MyClass.java:216)
       at package.MyApplication.onCreate(MyApplication.java:56)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
       at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7184)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7134)
       at android.app.ActivityThread.access$1500(ActivityThread.java:274)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2102)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8167)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

I went through this post, but I cannot find the setUpdateCurrent(true) method to use. How can I resolve this issue? Any help is highly appreciated.

Pooja Gaonkar
  • 1,546
  • 17
  • 27

0 Answers0