Fix broadcast unregister receiver

This commit is contained in:
J-Jamet
2018-07-01 11:54:46 +02:00
parent 27b0810688
commit 4cd2b153f4
2 changed files with 23 additions and 6 deletions

View File

@@ -28,6 +28,9 @@ public class KeyboardEntryNotificationService extends Service {
private int notificationId = 582;
private long notificationTimeoutMilliSecs;
private LockBroadcastReceiver lockBroadcastReceiver;
private PendingIntent pendingDeleteIntent;
public KeyboardEntryNotificationService() {
}
@@ -50,12 +53,13 @@ public class KeyboardEntryNotificationService extends Service {
}
// Register a lock receiver to stop notification service when lock on keyboard is performed
registerReceiver(new LockBroadcastReceiver() {
lockBroadcastReceiver = new LockBroadcastReceiver() {
@Override
public void onReceiveLock(Context context, Intent intent) {
context.stopService(new Intent(context, KeyboardEntryNotificationService.class));
}
}, new IntentFilter(LOCK_ACTION));
};
registerReceiver(lockBroadcastReceiver, new IntentFilter(LOCK_ACTION));
}
@Override
@@ -72,7 +76,7 @@ public class KeyboardEntryNotificationService extends Service {
private void newNotification() {
Intent deleteIntent = new Intent(this, NotificationDeleteBroadcastReceiver.class);
PendingIntent pendingDeleteIntent =
pendingDeleteIntent =
PendingIntent.getBroadcast(getApplicationContext(), 0, deleteIntent, 0);
if (MagikIME.getEntryKey() != null) {
@@ -128,8 +132,12 @@ public class KeyboardEntryNotificationService extends Service {
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(lockBroadcastReceiver);
pendingDeleteIntent.cancel();
notificationManager.cancel(notificationId);
super.onDestroy();
}
}

View File

@@ -60,18 +60,27 @@ public class MagikIME extends InputMethodService
private Keyboard keyboard;
private Keyboard keyboard_entry;
private LockBroadcastReceiver lockBroadcastReceiver;
@Override
public void onCreate() {
super.onCreate();
// Remove the entry and lock the keyboard when the lock signal is receive
registerReceiver(new LockBroadcastReceiver() {
lockBroadcastReceiver = new LockBroadcastReceiver() {
@Override
public void onReceiveLock(Context context, Intent intent) {
entryKey = null;
assignKeyboardView();
}
}, new IntentFilter(LOCK_ACTION));
};
registerReceiver(lockBroadcastReceiver, new IntentFilter(LOCK_ACTION));
}
@Override
public void onDestroy() {
unregisterReceiver(lockBroadcastReceiver);
super.onDestroy();
}
@Override