【发布时间】:2014-10-19 15:56:37
【问题描述】:
过程错误似乎没有很好的记录,我只能找到解决方法。相反,我对这个错误的原因以及如何防止它发生感兴趣,而不是如何通过重新启动、重新启动应用程序等手动处理它。
我的特定应用程序使用 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
);
这在大多数情况下都按预期工作。但是,该服务偶尔会无限期地启动失败,有时一次启动几个小时。以下错误每 30 秒出现一次,所以我知道我的警报正在尝试按计划启动 IntentService,但尝试失败并出现进程错误错误。
Unable to launch app com.example.android/10024 for service Intent { cmp=com.example.android/.MyService (has extras) }: process is bad
只需重新打开应用程序即可解决此问题。但我需要知道如何防止它!此服务的目的是在活动停止或销毁时在后台运行,因此它必须在没有任何用户交互或解决方法的情况下防止此错误。
【问题讨论】:
-
你的服务中有静态变量吗?
-
不确定,好几年没碰过代码,也没有权限了。但很可能是的。怎么会?
标签: android intentservice