I have an “alarm” app with several different alarm types that may be triggered at any given time. When the alarm goes off it adds a Status Bar Notification. When the user uses the “Clear All” button in the Status Bar, I want the Delete Intent to remove and close the Alarm Activity window from the screen. How can I achieve this? Because my Alarm Activity is NOT a Single Task activity, multiple activity windows can be created at once so I cannot just use an Intent with some data that the onNewIntent() function will run and close the Activity itself. I need to find a way to kill the alarm window from outside of the Activity.
Thanks for your help.
Hacky but 100% working solution: You can send a
Broadcastthat all activities are waiting for and that callsfinish()on them.onCreate of each Activity:
Then define it:
onDestroy:
Calling it:
Out of the box solution: Call by intent the first activity of the stack (if it’s always the same) with FLAG CLEAR_TOP (removing all activities except that one) and then on onNewIntent finish the last one.
I dunno if it works solution: I also found this: https://stackoverflow.com/a/6403577/327011 but i never worked with actions, so i’m not sure what will happen if multiple activities have the same action.
UPDATE:
You should use LocalBroadcastManager instead of “global” Broadcasts to avoid sending global broadcasts.
http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html