开发者

switching between activities in android

Hi I'm writing an app that ha开发者_运维问答s multiple activities. Right now it starts at the home screen, then when the user presses a button it starts a new activity and goes to another screen, then the user enters in information and presses a button to start another activity and another screen.

I have a menu setup so that from whatever the activity the user is in they can get back to the home screen. What I want it to do is kill all the current activities and just take the user right back to the home screen, so there is only one activity running again. How can I do this?


After sending the Intent just call finish() and the activity you're leaving will be closed.

Just don't do that on your "homescreen" activity. That way whenever the user starts an activity through one of your activities when he presses the back hardware button he is going to get back to your "homescreen" activity.


I figured it out. If you add myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); then when you run startActivity(myIntent); it clears all activities except the one myIntent is starting.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜