1->2->3 activities, at third "back button" I want to go to the first one
I have a MainActivity, then I call SecondActivity (where I choose a file whose data is given to ThirdActivity.
If back button is pushed, I want t开发者_C百科he app to go back yo MainActivity and not SecondActivity.
How can I do that?
There are two ways to do it.
In SecondActivity, call finish() immediately after you start Activity 3.
Pass in the NO_HISTORY flag in the Intent for SecondActivity when starting it in MainActivity.
Just after you call startActivity with the Intent for activity 3, call finish in activity 2:
//in activity 2
Intent intent = new Intent(...);
startActivity(intent);
finish();
You could also override onKeyPressed()
(or whatever it's called) for the back button and startActivity().
精彩评论