Make new activity take the place of the parent in the stack

I have read about activities, stacks and launch modes, but have a hard time understanding how to apply this info to my specific problem.

Basically what I want to do is to launch a new activity, and make sure that it takes the parent's place in the stack, rather than being placed on top of it in the stack. I have the following two scenarios:

  1. I have a login-activity. When the user logs in, a new activity is launched. When the user hits "back", I don't want him to be sent back to the login-activity, but rather to exit the program.

  2. I have an activity that is displayed in a tabhost (or rather in a framelayout inside a tabhost, I suppose). This activity has a button, an clicking on this launches a new activity. I would like this new activity to take the parents place. That is, i don't want to open a new full-screen activity, but instead I want it to take the parent's place inside the framelayout in the tabhost. Also, I don't want a press on the back-key to lead the user back to the parent activity.

I would appreciate it if anyone could point me in the right direction. Thanks in advance.


  1. All you need to do is call finish() in your Login Activity. That will remove it from the Activity Stack.

  2. This is a more difficult answer. My best suggestion here would be to either use a ViewFlipper and instead of starting a new Activity you can just manage switching the views out. Alternately, if you need the button to start a new Activity, you could use an ActivityGroup and manage the Activitys that way. They both have their own complexities, so you'll need to investigate which may work better for you.

In the first case, you need to call the finish() in your login activity. Also check this manifest settings to finish the activity when a new task is launched.

In the second case you may use two views as frames or a ViewFlipper. Then overwrite the keyevent to handle the back button click.,android.view.KeyEvent) Check if the user clicked when they are in the second view and show your first view. And if they are in the first view you may want to return false on the method that you overwrite to let the system to handle the event. [Probably close that activity]

Alternatively for the second option, it might be possible in some cases to just remove tabs and use the options menu. This way you can use your activities in a normal way.

Need Your Help

SVN: Move pending changes to a new branch

svn version-control branch

SVN is freaking me out right now. I've got some changes pending, that should not be comitted to the trunk, but rather to a branch that does not yet exist.

libpcap setfilter() function and packet loss

linux sip rtp pcap libpcap

this is my first question here @stackoverflow.

MPMoviePlayer done button Clicked Change The UIView Height

iphone xcode cocoa-touch ios4

I am using a MPMoviePlayer to display a video. I go into full screen and when the done button is clicked I want it to remove of the entire movie player from my view.