Start a new activity when the user clicks "Back" from another action

I have a splash screen activity when I run the application. the finish () function is launched on the splash screen, so the user will no longer see the splash screen when they press BACK from the last break activity. But instead of directly exiting the application, I want the application to display an exit splash screen that has different images than the startup splash screen, after which the application will be directly terminated.

So, I want it to be like this: Screensaver 1 (Start) → Activity A → Activity B → (Click Back) → Show Activity A → (Click again) → Screen Saver 2 (End)

How to do it?

Do I need to redefine the return button in Activity A or is there another way to show a new action when the user clicks the back button on event A?

+2
source share
5 answers

Why don't you undo the back button in step A with the start 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();
}
+5
source

You can simply override the finish () method by adding startActivity.

+1
source

,

  • A startActivityForResult

  • onActivityResult ,

+1

Depending on when you want the user to log out. If it is only in action A, you can simply override onKeyDown in this, otherwise override it in every active action.

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

Create and run your screen.

+1
source

A method of driving onBackPressed(). In this case, you can start your screensaver 2 / END activity.

0
source

All Articles