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 computational material science with a PhD in Physics from Friedrich-Schiller University Jena, Germany. I write efficient codes for simulating light-matter interactions at atomic scales. I like to develop Physics, DFT, and Machine Learning related apps and software from time to time. Can code in most of the popular languages. I like to share my knowledge in Physics and applications using this Blog and a YouTube channel.