gpt4 book ai didi

java - 应用程序在几秒钟的闪屏后将一个 Activity 移动到另一个 Activity 时崩溃

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:58 25 4
gpt4 key购买 nike

package com.example.firstclasswithahmad;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import java.security.PublicKey;
import javax.crypto.spec.DHPublicKeySpec;

public class SplashScreen extends AppCompatActivity {

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


Thread td= new Thread(){
public void run(){

try {
Thread.sleep(3000);
} catch (Exception e){
e.printStackTrace();
} finally {
Intent i=new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
}
}
};
td.start();
}
}

最佳答案

尝试在 onPostCreate() 方法中创建 Intent 。像这样:

@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
Thread td = new Thread() {
public void run() {

try {
Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
} finally {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
}
}
};
td.start();
}

关于java - 应用程序在几秒钟的闪屏后将一个 Activity 移动到另一个 Activity 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60120205/

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