在Application.onCreate()方法中访问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)
源代码
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());