尝试在初始屏幕中使用处理程序,如下所示:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come back when it presses back key
finish();
if (!mIsBackButtonPressed) {
// start the home screen if the back button wasn't pressed already
Intent intent = new Intent(Splash.this, Next_Activity.class);
startActivity(intent);
finish();
}
}
}, Constant.SPLASH_DURATION);
@Override
public void onBackPressed() {
// set the flag to true so the next activity won't start up
mIsBackButtonPressed = true;
super.onBackPressed();
}