如何避免JobScheduler中的IllegalStateException?

Pav*_*vel 14 android android-jobscheduler

在Application.onCreate()方法中访问JobScheduler时,我们在JobScheduler实现中观察到罕见的IllegalStateException.我想知道这是否是一个平台缺陷?

我们正在观察用户设备上的崩溃.几乎所有这些都是Android 5和5.1,但在Android 6(三星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)
Run Code Online (Sandbox Code Playgroud)

源代码

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());
Run Code Online (Sandbox Code Playgroud)

Bha*_*e O -2

Framework Job Scheduler支持API级别21以上。请通过下面的链接智能作业调度