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();
}
}
答案 0 :(得分:0)
尝试在onPostCreate()
方法内创建意图。像这样:
@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();
}