Start new activity when user click “Back” from another activity

╄→尐↘猪︶ㄣ 提交于 2019-12-24 01:47:17

问题


I have a splash screen activity at the startup of app. the startup splash screen has finish(), so user will not see startup splash screen anymore when they press BACK from the last remain activity. But instead of app directly exit, I want the app show a exit splash screen which has different images than startup splash screen, after that the app will directly end.

So I want it to be like this : Splash screen 1(Beginning) -> Activity A -> Activity B -> (Press Back) -> Show Activity A -> (Press Back Again) -> Splash screen 2 (End)

How to do that?

Do I have to override back button on Activity A or there's another method to show new activity when user press back button on Activity A ?


回答1:


Why don't you override back button on Activity A with starting activity code for Splash 2? I think this is the only solution.

For example:

@Override
public void onBackPressed() {
   Intent setIntent = new Intent(ActivityA.this, Splash2.class);
   startActivity(setIntent);
   finish();
}



回答2:


You can just override finish() method, adding startActivity.




回答3:


As simple as

  1. call your activity A from splash with startActivityForResult method without calling finish

  2. override onActivityResult of splash to show the end splash screen




回答4:


Depending on when you want the user to exit. If it's only in Activity A, you can simply override onKeyDown in that one, otherwise override it in each Activity you got.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        startActivity(new Intent("com.android.splashscreen"));
        finish();
    }
}

Create and start your end-splashscreen.




回答5:


over ride method of Activity A onBackPressed(). Inside this you can start your splash screen 2/END activity.



来源:https://stackoverflow.com/questions/10172466/start-new-activity-when-user-click-back-from-another-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!