我有一个启动画面,我想在我的主应用程序屏幕之前运行。但是,当计时器结束时,应用程序崩溃。关于为什么会发生这种情况的任何想法?提前致谢。
下面是参考代码
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Thread timer = new Thread() {
// Whatever is enclosed in the {} of method run(), runs when we
// start the application
public void run() {
try {
sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent openMainScreen = new Intent("com.package.Main_Screen");
startActivity(openMainScreen);
}
}
};
timer.start();
}
}