【问题标题】:Splash Screen does not appear in android application [duplicate]启动屏幕不会出现在android应用程序中[重复]
【发布时间】:2015-05-10 18:11:49
【问题描述】:
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();
}

}

【问题讨论】:

    标签: android splash-screen


    【解决方案1】:

    你不应该在你的主线程上调用Thread.sleep()。 试试这个:

            new Handler().postDelayed(new Runnable() {
    
            @Override
            public void run() {
                Intent LoginActivity = new Intent(SplashScreen.this, LoginActivity.class);
                startActivity(LoginActivity);
                finish();
            }
        }, 5000);
    

    【讨论】:

    • 我的应用程序似乎崩溃了,然后(5s 后)打开了登录屏幕!飞溅图像仍然消失!
    • @ĐôngNguyễnTrọng 删除:try { Thread.sleep(5000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); }
    • 我想在应用程序开始运行时在一定的持续时间(我自定义)设置闪屏主题。在登录活动中,还有另一个主题!
    猜你喜欢
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多