0

Possible Duplicate:
Removing an activity from the history stack

I've 1 question for the Android stack and the push stack process as stated below:

A->B->C->C->C->C->D

C will be repeatedly call itself until certain condition met.

i use the code below to start activity.

Intent intent = new Intent(this, MyActivity.class); startActivity(intent);

My problem is after activity D started i want straight away go back to activity B instead of go back activity C when press the back button.

A->B->C->C->C->C->D -----> A->B

I know i should use intent setFlags but i've no idea what to use http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/

Any suggestion?

Thanks in advance.

Edited: For this case Activity C is question page and the Activity D is the result page. A->B->Question 1->Question 2-> Question 3 -> Result.

I need to keep the history stack b4 activity D, this will allowed user to change the answer.

Community
  • 1
  • 1
Dylan
  • 1
  • 1

3 Answers3

1

for activity: c: try intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

Nissan911
  • 293
  • 1
  • 7
  • 17
1

Try Intent.FLAG_ACTIVITY_CLEAR_TOP each time you call startActivity() with the intent for B.

This will bring B to the top, popping all activities that were on top of it.

Matthew
  • 44,826
  • 10
  • 98
  • 87
1
@Override
public void onBackPressed() {
Intent i = new Intent(ACTIVITY_D, ACTIVITY_B);     
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        
    startActivity(i);
    return;
}

Override the onBackPressed() and set the FLAG_ACTIVITY_CLEAR_TOP flag. Place the function above under your activity D.

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
user638711
  • 11
  • 1