开发者

Optimal Activity Stack Order for a Main Menu button?

I'm developing an app that starts with a ma开发者_C百科in menu, and then continues through three different steps (activities) to a final activity where the task is marked complete. On this last activity, i have several additional options (add note, share, etc..) and i also have a return to main menu button.

My question is.. how do i stack the activities so that calling finish() on the final activity will return back to the first activity launched? i am currently just starting the new activity via an intent, so pressing back on this screen doesn't return me to home as i would like.

Sorry in advance for being so convoluted in my desc


If I understand you correctly, you want to remove the "steps" from the history stack when you press the main menu button in the final activity. If thats the case, instead of calling finish(), start the main menu activity with the flag Intent.FLAG_ACTIVITY_CLEAR_TOP:

Intent intent = new Intent(this, MainMenu.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);


with ref to http://developer.android.com/guide/appendix/faq/commontasks.html#opennewscreen,

Lifetime of the new screen: An activity can remove itself from the history stack by calling Activity.finish() on itself, or the activity that opened the screen can call Activity.finishActivity() on any screens that it opens to close them.

So you have to call the finish() as soon as you launch the Intent, some sample code

Intent i = new Intent(mContext, Name.class);
        startActivity(i);
        finish();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜