当我启动我的应用程序时,SplashScreen 会出现 3 秒,然后我进入 MainActivity,当我按下手机上的后退按钮时,我会回到 SplashScreen。当我按下后退按钮关闭应用程序时,如何调整? 我已经编写了这个
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == event.KEYCODE_BACK){
if (!pressedOnce){
pressedOnce = true;
Toast.makeText(getApplicationContext(), "Erneut drücken,um zu beenden.", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
pressedOnce = false;
}
}, 3000);
}else if (pressedOnce){
pressedOnce = false;
onBackPressed();
}
return true;
}
return super.onKeyDown(keyCode, event);
}
最佳答案
从带有标志的启动屏幕启动 MainActivity 并完成启动 Activity:
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
关于java - 启动后停用闪屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41771998/