开发者

What is the simplest way to make a three second timer in Android?

In the Android app I'm writing I want my activity to disp开发者_运维问答lay my company's logo and then launch a new activity three seconds after. I have the layout done and the graphic in the right place but I don't know how to make the timer.

What is the simplest, shortest way to create the three second timer?

Thank you very much in advance for all of the responses I receive.


Laurence Dawson's answer is fine, but (1) go straight to the Handler section, and (2) for your application you want postDelayed instead of postAtTime.

Actually there is a nearby answer very close to what you're looking for, except that instead of calling start, you want to instantiate a Handler and use postDelayed to schedule your Runnable 3 seconds later.


Heres a great page on the Android developer docs. They create a simple timer extending the "TimerTask".


here you go ... just tru threading .. thread will let ur activity sleep after some time and then start an intent .. and u must finish() activity when it is in pause mode :D see this

     Thread t = new Thread()
    {
        public void run()
        {
            try{
                sleep(3000);
            }catch(InterruptedException ie)
            {
                ie.printStackTrace();
            }finally
            {
        Intent i = new Intent(getApplicationContext(),  login.class);                         
                startActivity(i);
            }
        }
    }; t.start();
}
public void onPause()
{
    super.onPause();
    finish();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜