这个过程是错误的错误似乎没有很好的记录,我只能找到变通方法.我对此错误的原因以及如何防止它发生感兴趣,而不是如何通过重新启动,重新启动应用程序等手动处理它.
我的特定应用程序使用AlarmManager启动IntentService,每30秒运行约10秒.这是在创建应用程序时调用的:
Intent serviceIntent = new Intent(appContext, MyService.class);
serviceIntent.putExtra("service_extra", extra);
launchService = PendingIntent.getService(
appContext,
LAUNCH_SERVICE_REQUEST_CODE,
scanIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
alarmManager.setInexactRepeating(
AlarmManager.RTC,
System.currentTimeMillis() + interval,
interval,
launchService
);
Run Code Online (Sandbox Code Playgroud)
这在大多数情况下按预期工作.但是,有时候服务无法无限期启动,有时几小时无法启动.每隔约30秒就会出现以下错误,因此我知道我的警报正在尝试按计划启动IntentService,但尝试失败并且进程错误.
Unable to launch app com.example.android/10024 for service Intent { cmp=com.example.android/.MyService (has extras) }: process is bad
Run Code Online (Sandbox Code Playgroud)
只需重新打开应用即可解决此问题.但我需要知道如何预防它!此服务的目的是在活动停止或销毁时在后台运行,因此必须在没有任何用户交互或解决方法的情况下防止此错误.