我什么时候应该使用unregisterReceiver?在onPause(),onDestroy()或onStop()?
注意:我需要该服务在后台运行.
更新:
我发布接收器的异常null.
活动已泄露意图接收器是你错过了呼叫 unregisterReceiver();
请告诉我是否有什么问题,这是我的代码:
private boolean processedObstacleReceiverStarted;
private boolean mainNotificationReceiverStarted;
protected void onResume() {
super.onResume();
try {
registerReceivers();
} catch (Exception e) {
Log.e(MatabbatManager.TAG,
"MAINActivity: could not register receiver for Matanbbat Action "
+ e.getMessage());
}
}
private void registerReceivers() {
if (!mainNotificationReceiverStarted) {
mainNotificationReceiver = new MainNotificationReceiver();
IntentFilter notificationIntent = new IntentFilter();
notificationIntent
.addAction(MatabbatManager.MATABAT_LOCATION_ACTION);
notificationIntent
.addAction(MatabbatManager.MATABAT_New_DATA_RECEIVED);
notificationIntent
.addAction(MatabbatManager.STATUS_NOTIFCATION_ACTION);
registerReceiver(mainNotificationReceiver, notificationIntent);
mainNotificationReceiverStarted = true;
}
if (!processedObstacleReceiverStarted) {
processedObstacleReceiver …Run Code Online (Sandbox Code Playgroud) 我的应用程序(仍然是WIP)在不同设备上运行良好.但是突然它拒绝启动华为Honor 7(Android 6.0/EMUI 4.0.3).Logcat给了我以下内容:
__PRE__
其次是
__PRE__
此错误发生9次spli_lib_slice_N_apk.apk-parts.我真的不知道,它可能是什么,特别是因为它运行良好,直到今天.我没有对代码进行任何更改.据我所知,我也不使用任何multidex.
任何提示都表示赞赏,谢谢!
更新2017年7月13日: 我用appstart记录了它始终有效的设备,我得到了与上面相同的"错误".所以看来,这些消息可能是正常的...在此之后我查看了故障设备的崩溃日志,并在我上面发布的错误后不久发现了以下行:
__PRE__
似乎这个过程被Sigkill 9杀死了,另请参见SE:App死于"发送信号".但没有例外或其他信息
但我又不知道是什么导致了这一点.在此之后,我清除了机器人应用程序首选项中的应用程序数据,突然应用程序再次启动.调查将继续......