catch exception when unregistering receivers that have not been registered before

This commit is contained in:
Daniel Gultsch 2015-10-08 00:52:04 +02:00
parent f81e44d339
commit e65068d226
1 changed files with 11 additions and 3 deletions

View File

@ -662,7 +662,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override @Override
public void onDestroy() { public void onDestroy() {
unregisterReceiver(this.mEventReceiver); try {
unregisterReceiver(this.mEventReceiver);
} catch (IllegalArgumentException e) {
//ignored
}
super.onDestroy(); super.onDestroy();
} }
@ -672,12 +676,16 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(this.mEventReceiver, filter); registerReceiver(this.mEventReceiver, filter);
} else { } else {
unregisterReceiver(this.mEventReceiver); try {
unregisterReceiver(this.mEventReceiver);
} catch (IllegalArgumentException e) {
//ignored
}
} }
} }
public void toggleForegroundService() { public void toggleForegroundService() {
if (getPreferences().getBoolean("keep_foreground_service",false)) { if (getPreferences().getBoolean("keep_foreground_service", false)) {
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification()); startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
} else { } else {
stopForeground(true); stopForeground(true);