In my application, I\'ve two activities. First is a splash screen, which simply shows the application name and few other info. Upon clicking on the splash screen activity, I
In addition to the above answers, you should note that:
1: by calling the finish() method, the Splash activity will close after execution, meaning that it will not be available in the stack.
@Override
protected void onCreate(Bundle saveInstsnceState){
super.onCreate( saveInstanceState);
\\ do something here
Intent intentSplash = new Intent(SplashActivity.this, NextActivity.class);
StartActivity(intentSplash);
finish ();
}
You will achieve your aim using the method above but...
2: If you want to prevent your users from force exiting the app (pressing back button) while the splash activity in still ongoing which is the best practice in android, then you need to call the onBackPressed () method.
Class NoBackSplash{
@Override
protected void onCreate(Bundle saveInstsnceState){
super.onCreate( saveInstanceState);
\\ do something here
Intent intentSplash = new Intent(SplashActivity.this, NextActivity.class);
StartActivity(intentSplash);
finish ();
}
@Override
public void OnBackPressed(){
};
}
With this OnBackPressed() method, your splash activity will not be force to exit no matter how hard the user try.
In your AndroidManifest.xml
file, add android:noHistory="true"
attribute in your splash screen <activity>
.
As I understand, you want the splash activity to not show after changing activity. You should note activities save On Stack and with starting new activity push on it and with finish you pop on top stack. I think that if you the call finish()
method your problem fix as in your splash screen activity where you call StartActivity insert finish()
after
public void onClick(View v) {
Intent intent = new Intent(Main.this, Splash.class);
startActivity(intent);
finish();
}
Hope to be useful :)
You can just call
finish();
In your Splash screen when you jump to the second screen.