As Activities are opened by the user, they're stacked up on the view stack. and as the user finishes an Activity by any means, it is popped out of the view stack.
Now, I have a situation where the user has opened the app's home screen, and has successively opened multiple activities, on top of the home screen. In each activity, there's a control which lets the user see the home screen again.
As i can think开发者_JAVA百科, there can be two approaches to get this:
- On the press of that control, pop the home screen from the bottom of the view stack and push it on the top of it.
- As the control is pressed, start popping each of the current screen until the home screen becomes the current screen.
I know there's some way in Android to do at least one of this, or something like this. I just can't remember what was it.
Please help me choose the better approach, and let me know the way (the code, specifically) to do it.
Thanks a lot :)
(Please edit the title/text if it isn't appropriate)
try something like this
Intent i = new Intent();
i.putExtra(EXTRA_KEY_ARTIST, id);
i.setClass(this, ArtistActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
That's all when you set the the FLAG_ACTIVITY_SINGLE_TOP property it wont start a new activity but will show your activity intially created if its not destroyed yet,
But if your activity is the starting activity then you can put it like this
<activity
android:name=".ArtistActivity"
android:label="Artist"
android:launchMode="singleTop">
</activity>
精彩评论