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

[wpedon id="7041" align="center"]

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.