Android App development in some cases need to have a delay function, such as the app home 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. TimerTask task = new TimerTask () { 2. public void Run () { 3. Execute the Task 4. } 5.}; 6. Timer timer = new timer (); Timer.schedule (task, delay);
Third,android message processing
New Handler (). postdelayed (New Runnable () {public void run () { //execute the task }
We recommend the use of a third
Delayed execution of a task in Android