Android 视图之间的时间延迟

Android 视图之间的时间延迟,android,time,delay,Android,Time,Delay,我不确定,是什么阻止了这一切。我的代码设置导致3秒的时间延迟,但视图不工作,它保持黑色,3秒后切换到下一个屏幕。我想,我正在做延时,Android中还没有调用一些东西来显示布局 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); start = System.currentTimeMillis(); setContentView(R.layou

我不确定,是什么阻止了这一切。我的代码设置导致3秒的时间延迟,但视图不工作,它保持黑色,3秒后切换到下一个屏幕。我想,我正在做延时,Android中还没有调用一些东西来显示布局

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);     
    start = System.currentTimeMillis();
    setContentView(R.layout.team);
}

protected void onStart()
{
    super.onStart();        
    while(game)
    {
        now = System.currentTimeMillis();
        if (now - start >= 5000)
        {
            game = false;
            Intent about = new Intent(this, SplashScreen.class);
            startActivity(about);
        }
    }
}

您应该使用Timer类来启动新活动。

我相信您希望实现一个延迟几秒的屏幕,然后启动主应用程序。就像主应用程序启动前的启动屏幕一样,对吗

那么这将帮助你

 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /** set time to splash out */
    final int welcomeScreenDisplay = 4000;
    /** create a thread to show splash up to splash time */
    Thread welcomeThread = new Thread() {

    int wait = 0;

    @Override
    public void run() {
    try {
    super.run();
    /**
    * use while to get the splash time. Use sleep() to increase
    * the wait variable for every 100L.
    */
    while (wait < welcomeScreenDisplay) {
    sleep(100);
    wait += 100;
    }
    } catch (Exception e) {
    System.out.println("EXc=" + e);
    } finally {
    /**
    * Called after splash times up. Do some action after splash
    * times up. Here we moved to another main activity class
    */
    startActivity(new Intent(CurrentActivity.this, NextActivity.class));
    finish();
    }
    }
    };
    welcomeThread.start();
}
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/**设定泼水的时间*/
最终屏幕显示=4000;
/**创建一个线程以显示从启动到启动时间的启动*/
线程welcomeThread=新线程(){
int wait=0;
@凌驾
公开募捐{
试一试{
super.run();
/**
*使用while获得启动时间。使用sleep()增加启动时间
*每100升的等待变量。
*/
while(等待
这是一个延迟4秒的屏幕