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:
-
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.
-
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.
All you need to do is call
finish()in your Login Activity. That will remove it from the Activity Stack.This is a more difficult answer. My best suggestion here would be to either use a
ViewFlipperand instead of starting a newActivityyou can just manage switching the views out. Alternately, if you need the button to start a newActivity, you could use anActivityGroupand manage theActivitys that way. They both have their own complexities, so you’ll need to investigate which may work better for you.