I am running into a peculiar issue with an app which has multiple Activities. I have a screen manager class that is bound to a service. The service polls a server for data. The screen manager starts Activity A, B, or C, based on the data. It will also allow the user to select to display the other Activities or it may swap out an Activity automatically based on new data from the service. Currently all the navigation works great and if the user presses Home, the applicable Activity comes back to the foreground when the user presses the apps icon from the Android home screen or the recently run apps list.
I then had to implement a new feature to display an icon and notification. I first implemented this by only displaying the notification when the Activities were no longer visible by setting it in each Activities onPause. Worked like a charm and gave the user a third option to redisplay the app after Home button press. However if the data from the server (when the app is not displayed) causes the screen manager to update the Activity to be displayed I have issues. I think my Activity stack is getting screwed up. I have since tried a little different model where the screen Manager handles the notifications and always displays the notification, updating it with a new Intent whenever an Activity is updated, but its still not cutting it.
When the app is minimized and the data changes I can see the screen manager call the startActivityForResult on the new Activity and it seems like Android knows we are minimized and does not display the Activity. I can then also the screen Manager call to finish on the old top Activity.
Each Activity currently has the flag set to singleTop in the manifest and FLAG_ACTIVITY_SINGLE_TOP in the code. When the data hasn't changed on the server, I pull the app back up using any of the above I get what I expect and the Activity's onNewIntent is called. However when the data has changed and the user calls up the app via the notification it calls the Activities onCreate. The Activity does come up and runs, but then pressing back takes me to what seems like another instance of the same Activity instead of exiting. I just took a closer look at my logcat and I see 2 calls to the Activity's onResume, but then no doubles after that.
I feel like maybe I'm just missing something simple like another intent flag on the notification's Intent? Thanks for any ideas!