Delayed execution of a task in Android
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
New Thread (New Runnable () {
public void Run () {
Thread.Sleep (XXXX);
Handler.sendmessage ();----tell the main thread to perform a task
}
}). Start
Second, the delay device
TimerTask task = new TimerTask () {
public void Run () {
Execute the Task
}
};
Timer timer = new timer ();
Timer.schedule (task, delay);
Third, Android message processing
New Handler (). postdelayed (New Runnable () {
public void Run () {
Execute the Task
}
}, delay);
Backup OSC
Delayed execution of a task in Android (base standby)