gpt4 book ai didi

java - 启动后停用闪屏

转载 作者:行者123 更新时间:2023-12-01 08:59:52 24 4
gpt4 key购买 nike

当我启动我的应用程序时,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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com