The Thread.sleep(1000) is probably not the best idea on Android
because responsiveness is an issue if you care about user ratings ;-).
With Thread.sleep() the app just sit's there and waits and won't
respond to user input.

I would recommend using something like:

        private static final int WAKE_UP_DELAY = 5000;
        private static final int WAKE_UP_CALL = 0;
        private Handler handler;

        private Runnable wakeUpCall = new Runnable() {
                @Override
                public void run() {
                        handler.sendEmptyMessage(WAKE_UP_CALL);
                }
        };

        handler = new Handler(new Handler.Callback() {
                @Override
                public boolean handleMessage(Message msg) {
                        if (msg.what==WAKE_UP_CALL) {
                                // change message, your code goes here...
                                // let's start the timer again
                                handler.postDelayed(wakeUpCall, WAKE_UP_DELAY);
                                return true;
                        }
                        return false;
                }
        }
        );

        handler.postDelayed(wakeUpCall, WAKE_UP_DELAY);

        // do something...

The "// do something" part is the important difference to the
Thread.sleep(). With the latter the app sleeps while with the my
version the app can do whatever the app is supposed to do.
And after a certain time (5 seconds in my example) you can change the
message or whatever else there is to do.

Emanuel Moecklin
1gravity LLC
"A big bang experience for our customers!"

On Nov 29, 2:55 pm, dipti <[email protected]> wrote:
> You can use java's Thread.sleep(1000) . This will make the application
> pause for 1 sec ( 1000 millisec )
>
> On Nov 29, 6:49 am, charlest <[email protected]> wrote:> I want to 
> display a message on the screen, have it displayed for 60
> > seconds, then display another message. There is nothing specific going
> > on during the 60 seconds that I'm waiting to complete, so AsyncTask
> > doesn't seem to apply. Does someone have a generic code snippet that
> > does this so that I can use it in other places as needed?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to