开发者

Android activity stack question [duplicate]

开发者 https://www.devze.com 2023-02-13 18:32 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Removing an activity from the history stack
This question already has answers here: Closed 11 years ago.

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.


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


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.


@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.

0

精彩评论

暂无评论...
验证码 换一张
取 消