I have a splash screen and if I press the back button while the splash activity is running this activity is closed but the next activity after the splash (after 2 seconds) will be open. I would like to set the back button to close the splash a开发者_C百科ctivity but to open immediately the next activity or to close the whole application.
You need to override the back-button with this:
@Override
public void onBackPressed(){
Intent i1 = new Intent(getApplicationContext(), NextActivity.class);
startActivity(i1);
return;
This will take you to the next Activity when you pres the button. If you want to close the app try this:
@Override
public void onBackPressed(){
moveTaskToBack(true);
return;
精彩评论