开发者

1->2->3 activities, at third "back button" I want to go to the first one

开发者 https://www.devze.com 2023-04-08 00:55 出处:网络
I have a MainActivity, then I call SecondActivity (where I choose a file whose data is given to ThirdActivity.

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.

  1. In SecondActivity, call finish() immediately after you start Activity 3.

  2. 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().

0

精彩评论

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