android studio项目启动屏幕未正常关闭,应用程序运行完美但退出应用程序后启动屏幕显示,为什么

tkqqtvp1  于 2021-07-06  发布在  Java
关注(0)|答案(2)|浏览(397)

关闭。这个问题需要细节或清晰。它目前不接受答案。
**想改进这个问题吗?**通过编辑这个帖子来添加细节并澄清问题。

5个月前关门了。
改进这个问题
android studio项目启动屏幕关闭不正常,应用程序运行完美但退出后应用程序启动屏幕显示,为什么
还可以添加xml和java的图像
[启动屏幕错误][1]

fsi0uk1n

fsi0uk1n1#

因为您没有完成splash活动,所以这里有一个正确的方法来进行splash(尽管我不推荐这种方法用于splash):

Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while (waited < 5000) {
                        sleep(100);
                        waited += 100;
                    }
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(intent);
                    SplashActivity.this.finish();
                } catch (InterruptedException e) {

                } finally {
                    SplashActivity.this.finish();
                }

            }
        };
        thread.start();
v1uwarro

v1uwarro2#

请尝试以下代码:

new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // This method will be executed once the timer is over
                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }, 5000);

相关问题