How to avoid going back to the Splash Screen Activity on the press of Back Button? [SOLVED] – Android Studio


To prevent the user from going back to the splash screen on pressing the ‘back’ button, just add the following line to the splash screen activity, in your AndroiManifest.xml:

android:noHistory="true"

This attribute will prevent the splash screen from going to the stack, and thus it won’t be displayed at t he press of the ‘back’ button.

You could also do this programatically, by calling finish(); after calling startActivity to start the MainActivity.
Example:

public void onClick(View v) {
    Intent intent = new Intent(Main.this, Splash.class);
    startActivity(intent);
    finish();
}

Reference: Stack Exchange

I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.



Leave a Reply

Your email address will not be published. Required fields are marked *