【问题标题】:android time delay between viewsandroid视图之间的时间延迟
【发布时间】:2011-06-24 10:14:05
【问题描述】:

我不确定,是什么阻止了它的工作。我有代码设置导致 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);
        }
    }
}

【问题讨论】:

    标签: android time delay


    【解决方案1】:

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

    那么这对你有帮助!

     /** 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 秒的屏幕。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-20
        • 2016-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多