I really don’t understand how all this flags working since I do exactly what the doc said, and it didn’t solved my problem. My activity is launching like this : (first) Activity A -> Activity B -> (second) Activity A. If I press button back, it goes back to Activity B -> Activity A -> Exit application. Now I want from second Activity A stated from Activity B, when press back, it will skip Activity B and first Activity A, and Exit application right away. Here’s the code:
From A to B:
TabActivityGroupAbs parentActivity = (TabActivityGroupAbs) ((Activity) ctx).getParent();
detailIntent = new Intent(parentActivity, B.class);
parentActivity.startChildActivity("BFromA", detailIntent);
From B to A:
TabActivityGroupAbs parentActivity = (TabActivityGroupAbs) ((Activity) ctx).getParent();
detailIntent = new Intent(parentActivity, A.class);
detailIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
detailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
parentActivity.startChildActivity("AFromB", detailIntent);
From B to A, I add the flags FLAG_ACTIVITY_CLEAR_TOP. But it didn’t clear anything. When I pressed back, it still went to Activity B, and then A again. What did I do wrong?
And it seems like none of the flags are working at all. From A to B, I put:
detailIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
It supposed to prevent B be put to activity stack. But it’s not. From the second activity A, it still go back to B when press back.
Now what should I do to exit application and not go back to B from the second activity A.
EDIT: I forgot to mention. From B to A, if I called finish() to kill activity B, then from second activity A, when press back, it go back to first activity A. Why activity A have 2 instance here though I set FLAG_ACTIVITY_CLEAR_TOP? Really strange.
You can use the following methods to start and close child activity
Example: