public class SplashScreen extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
Intent LoginActivity = new Intent(SplashScreen.this, LoginActivity.class);
startActivity(LoginActivity);
finish();
}
}
带有activity_splash_screen
的是启动画面的布局。我的应用程序显示白屏而不是我的启动图像。
当我没有设置下一个动作LoginActivity
时,我的启动图像会回来!
public class SplashScreen extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
// Intent LoginActivity = new Intent(SplashScreen.this, LoginActivity.class);
// startActivity(LoginActivity);
finish();
}
}
答案 0 :(得分:1)
您不应该在主线程上调用Thread.sleep()
。
试试这个:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent LoginActivity = new Intent(SplashScreen.this, LoginActivity.class);
startActivity(LoginActivity);
finish();
}
}, 5000);