How to control the flow of activity - the "Back" or "Home" button
I have 3 actions in my application:
Activity1 -> Activity2 -> Activity3
Inside Activity3, if the user clicks Back, I would like to return to Activity2. In the Activity3 onPause event, I added a statement finish(). Perhaps this is not even necessary, but I wanted to make sure that this activity was cleared. It works great.
However, although in Activity3, if the user clicks "Home" or launches a new application (via the notification bar or some other means), I want both Activity3 and Activity2 to finish. If the user returns to this application, he must resume work with Activity1.
I figured out how to do one or the other, but I can't figure out how to handle both cases, if possible. Can I lock the back button in Activity3 and send a message back to Activity2 to tell her not to finish()? It seems that Actions follow the same flow of the life cycle (Pause, Stop), no matter what you do to send them to the background.
To answer the question why I want this behavior, imagine that Activity1this is the login screen, Activity2is the selection screen, and Activity3is the content screen. If I click Back on the content page, I want to be able to make a new selection. If I exit through any other means (Home, notification bar), I want the user to be "logged out".
Thanks in advance for your help.
, . , - .
onPause Activity2, Activity3 finish(). , "" "", . , , Activity1 ( ).
Activity3 onKeyDown "". Activity2 , Pause, Activity2 Activity3. Activity2 Activity3 . Activity3 onKeyDown:
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_BACK) {
Intent Act2Intent = new Intent(thisActivity, Activity2.class);
startActivity(Act2Intent);
finish();
return true;
}
return false;
}