[英]App crashed moving one activity to another activity after some seconds splash screen
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()
方法中创建意图。 像这样:
@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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.