android View 之间的时间延迟

标签 android time delay

我不确定是什么阻止了它的工作。我的代码设置会导致 3 秒的时间延迟,但 View 无法正常工作,它保持黑色,然后在 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);
        }
    }
}

最佳答案

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

那么这会对你有所帮助!

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

这是一个延迟 4 秒的屏幕。

关于android View 之间的时间延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466388/

相关文章:

android - 从数据库中读取一个值

java - Drawable 不显示在 ImageView 中

c - 尝试使用 clock_gettime(),但从 time.h 中得到大量 "undeclared"错误

date - 如何在 Hive 中将时间戳(秒和毫秒之间的点)转换为日期(yyyyMMdd)?

c++ - 延迟函数调用,如何传递参数?

android - SensorEvent onChanged 多线程?

javascript - 如何设置两个js函数之间的延迟?

android - Gradle 插件 'com.apollographql.apollo' 未在 Android Studio 中同步

java.lang.RuntimeException : Unknown layout animation name: set

R Studio 随机化日期和时间