Reputation: 125
I'm working on C2DM notification for an Android Application and I'd like to open my application when user click on the notification. There is no problem for that, this is pretty easy. The problem is that when the application is launching (after clicking on the notification), if some activity was previously opened, the launched activity seems to be added to the actual activity stack, what is a problem regarding to the complexity of my application (there is a lot of activity, some with static fields).
To solve the problem, 2 solutions would be OK:
1) Do not call a specific activity but just ask to my application to open (like when I click on the application icon on the home screen: Open the first activity if the application was closed or just bring the application to the front if was opened (but was in background)).
2) Clear all the activity stack and launch a specific activity.
But I didn't succeed to do one of both solution. Even using intent flag (like http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP).
Can somebody help me to solve this problem?
Thanks
PS: Sorry for my poor English, I'm from Belgium :-)
Upvotes: 2
Views: 1087
Reputation: 5586
It's not what you asked to do but you can add the attribute android:launchMode="singleTask"
to the activity you will be calling out of this notification and it won't create a new activity if one this instance already exists.
You could possibly also use the ActivityManager.killBackgroundProcesses(String packageName)
to remove background processes but I have never tried this and it isn't advised or use the ChriZzZ suggestion and manage your activities a bit tighter.
Upvotes: 1
Reputation: 966
Sounds like you are searching for FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
If set, this marks a point in the task's activity stack that should be cleared when the task is reset. That is, the next time the task is brought to the foreground with FLAG_ACTIVITY_RESET_TASK_IF_NEEDED (typically as a result of the user re-launching it from home)
Upvotes: 0