Skip to content

Commit 1a44f3c

Browse files
committed
do synchronized action listeners
1 parent b26442b commit 1a44f3c

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

app/src/main/java/com/scrappers/dbtraining/notifications/OnActionsListener.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@ public OnActionsListener() {
2727
@Override
2828
protected void onHandleIntent(@Nullable Intent notificationIntent) {
2929
assert notificationIntent != null;
30-
if(notificationIntent.getAction().equals(BackgroundTask.ACTION_TEST_JME)){
31-
//start another explicit intent implicitly from an IntentService which is directed using a PendingIntent from a notification action
32-
Intent intent = new Intent(getApplication(), HolderActivity.class);
33-
//start an activity from outside the context flag
34-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
35-
startActivity(intent);
36-
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
37-
notificationManager.deleteNotificationChannel(NotificationUtils.CHANNEL_ID);
38-
notificationManager.cancelAll();
39-
Toast.makeText(getApplicationContext(), "Powered By Jme", LENGTH_LONG).show();
40-
}else if(notificationIntent.getAction().equals(BackgroundTask.ACTION_DISMISS)){
41-
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
42-
notificationManager.deleteNotificationChannel(NotificationUtils.CHANNEL_ID);
43-
notificationManager.cancelAll();
44-
30+
synchronized(this){
31+
if ( notificationIntent.getAction().equals(BackgroundTask.ACTION_TEST_JME) ){
32+
//start another explicit intent implicitly from an IntentService which is directed using a PendingIntent from a notification action
33+
Intent intent = new Intent(getApplication(), HolderActivity.class);
34+
//start an activity from outside the context flag
35+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
36+
startActivity(intent);
37+
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
38+
notificationManager.deleteNotificationChannel(NotificationUtils.CHANNEL_ID);
39+
notificationManager.cancelAll();
40+
Toast.makeText(getApplicationContext(), "Powered By Jme", LENGTH_LONG).show();
41+
} else if ( notificationIntent.getAction().equals(BackgroundTask.ACTION_DISMISS) ){
42+
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
43+
notificationManager.deleteNotificationChannel(NotificationUtils.CHANNEL_ID);
44+
notificationManager.cancelAll();
45+
}
4546
}
4647
}
4748
}

0 commit comments

Comments
 (0)