15

We observe a rare IllegalStateException inside JobScheduler implementation when JobScheduler is accessed within Application.onCreate() method. I wonder if this is a platform flaw?

We are observing this crash on our users devices. Almost all of them are Android 5 and 5.1, but one crash happened on Android 6 (Samsung Galaxy S5 Duos).

java.lang.IllegalStateException: 
  at android.os.Parcel.readException (Parcel.java:1711)
  at android.os.Parcel.readException (Parcel.java:1653)
  at android.app.job.IJobScheduler$Stub$Proxy.schedule (IJobScheduler.java:158)
  at android.app.JobSchedulerImpl.schedule (JobSchedulerImpl.java:42)
  at yo.host.job.a.a (SourceFile:237)
  at yo.widget.WidgetController.b (SourceFile:92)
  at yo.host.Host.q (SourceFile:680)
  at yo.host.Host.onCreate (SourceFile:505)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1032)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:5970)

Source code

int jobId = 1;
JobInfo.Builder builder = new JobInfo.Builder(
    jobId,
    new ComponentName(
        Host.geti().getPackageName(),
        WeatherJobService.class.getName()
    )
);

builder.setPersisted(true);//Restart the job after reboot.
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);

PersistableBundle bundle = new PersistableBundle();
bundle.putString(WeatherJobService.EXTRA_LOCATION_ID, locationId);
bundle.putString(WeatherJobService.EXTRA_REQUEST_ID, requestId);
bundle.putString(WeatherJobService.EXTRA_CLIENT_ITEM, clientItem);
builder.setExtras(bundle);

int errorCode = getJobScheduler().schedule(builder.build());
ColdFire
  • 6,764
  • 6
  • 35
  • 51
Pavel
  • 2,610
  • 3
  • 31
  • 50
  • Do you mean JobScheduler is created within Application#onCreate() ? – CoXier Feb 28 '18 at 09:07
  • Technically, the system is creating JobScheduler. This is what we are doing in Application.onCreate() myJobScheduler = (JobScheduler)getSystemService(Context.JOB_SCHEDULER_SERVICE); myJobScheduler.schedule(builder.build()); – Pavel Feb 28 '18 at 10:35
  • 1
    Possibly relevant: https://stackoverflow.com/questions/18858320/nullpointerexception-etc-from-parcel-readexception. At least, that question explains why the stack trace above is so uninformative. – Ilmari Karonen Mar 20 '18 at 11:50
  • 1
    Considered including your SourceFile... or just ANY code at all, to see broader context, because.... what is builder.build()? I just mean this could help anyone to answer your question ;) – Piotr Z Mar 20 '18 at 21:30
  • Thanks, Piotr. I have added a portion of code where the Job is scheduled. Let me know if you need more details. – Pavel Mar 21 '18 at 06:11

2 Answers2

1

You might be experiencing the exception described here: https://github.com/yigit/android-priority-jobqueue/issues/202

Fatal Exception: java.lang.IllegalStateException: Apps may not schedule more than 100 distinct jobs
  at android.os.Parcel.readException(Parcel.java:1674)
  at android.os.Parcel.readException(Parcel.java:1619)
  at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:158)
  at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:42)

In which case you'd want to avoid scheduling more than 100 jobs.

Greyson Parrelli
  • 788
  • 1
  • 8
  • 12
-2

Framework Job Scheduler supports above API level 21. Please go through the link below intelligent job scheduling

Bhagyashree O
  • 123
  • 1
  • 3
  • 13