启动画面不会出现在Android应用程序中

时间:2015-05-10 18:11:50

标签: android splash-screen

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();
}

}

1 个答案:

答案 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);