【问题标题】:Main Activity is not coming after Splash screen启动画面后没有出现主要活动
【发布时间】:2021-11-02 18:43:39
【问题描述】:

这是我的代码。启动屏幕后主要活动不会运行,并且没有出现错误。启动画面后应用程序崩溃。

飞溅活动

package com.example.collegematch;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        getSupportActionBar().hide();   


        Thread thread = new Thread(){

            public void run(){
                try {
                    sleep(2000);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
                finally {
                    Intent intent = new Intent(SplashActivity.this , MainActivity.class);
                    startActivity(intent);
                    finish();

                }
            }
        };
        thread.start();
    }
}

【问题讨论】:

标签: java android android-layout android-activity splash-screen


【解决方案1】:

将代码改为:

val handler = Handler(mainLooper)
        handler.postDelayed(
            {
                startActivity(
                    new Intent(SplashActivity.this , MainActivity.class)
                );
                finish();
            }, 1000
        )

不建议制作这样的闪屏。请阅读this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    相关资源
    最近更新 更多