I managed to get a notification from our app to appear on the Notification bar at the top of the screen, whenever it receives a push. My application is a hierarchy of views. I have my main screen with a listview. When one of these listview items is clicked it opens a summary screen (also containing a listview), and when one of the summary screen listview items is clicked it opens a details screen (last screen in the hierarchy). The user can hit the back button to travel back up the hierarchy to the main screen (or home screen).
Now, my application, and most apps for that matter, tend to run in the background until the back button is hit enough times. I set my Notification to launch an instance of mainScreen when it is clicked. The thing is if the app is already running and I do this it creates another main screen over all the other screens, so when the user hits the back button on the main screen (expecting to exit out of the app) he’ll go back to whatever screen was active when he left my app running in the background.
So, I could potentially go back up the hierarchy like this:
mainScreen -> detailsScreen -> summaryScreen -> mainScreen -> EXIT
Is there a way I can just kill the application and start a fresh instance when the user clicks my notification? How are these notification clicks normally handled?
Hope this makes sense.
Thanks.
(Edtied: Got everything working as expected except for one problem. I wasn’t completely honest when I said that the detailsScreen(activityB in your example) was the last in the hierarchy. On this screen the user actually has the option to view a map
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=" + depLatitude + "," + depLongitude + "(" + name + ")"));
startActivity(intent);
When I press back on the map, the ideal situation would be for it to return to the detailsScreen, but in this case it goes right back to the mainScreen.
Any ideas?
)
You can use Reorder to front attribute and get the same instance of mainScreen to the top.
For destroying activities which you dont want as soon as they go in the background use noHistory attribute
Launch Activity A from MainActivity
In this code snippet we are launching Activity A in the standard mode.
Launch Activity B from Activity A
Activity B is launched with Intent flag : Intent.FLAG_ACTIVITY_REORDER_TO_FRONT from Activity A
Launch Activity A from Activity B
When the Activity A is launched from Activity B the previous instance of the activity gets reordered to the front instead of creating a new one
No History
Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it’s no longer visible on screen — “true” if it should be finished, and “false” if not. The default value is “false”.
A value of “true” means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.