Android app Development in some cases need to have a delay function, such as the app home page display 3 seconds, and then automatically jump to the login page situation, which is like a preload, but this preload may be completed in an instant, support less than 3 seconds, which is required to do time-delay processing.
Here are three ways to do this:
One, thread
1 New Thread (new Runnable () { 2. Public void run () { 3. Thread.Sleep (XXXX); 4. Handler.sendmessage ();---- tell the main thread to perform task 5. } 6.}). Start
Second, the delay device
1 New TimerTask () { 2. Public void run () { 3. // Execute the Task 4 . } 5 . }; 6 New Timer (); Timer.schedule (task, delay);
Third, Android message processing
New Handler (). postdelayed (new Runnable () { publicvoid run () { // Execute the Task } }, delay);
We recommend the use of a third
Reference: http://blog.csdn.net/qinde025/article/details/6828723
Delayed execution of a task in Android