Delay in running a task in Android
Android app development requires a latency function in some situations. For example, if the app homepage is displayed for 3 seconds and then automatically jumps to the logon page, this is like a pre-load, however, the pre-loading may be completed in an instant and takes less than 3 seconds. This requires you to perform latency processing.
There are three methods:
I. threads
1. new thread (New runnable () {2. public void run () {3. thread. sleep (XXXX); 4. handler. sendmessage (); ---- tell the main thread to execute the Task 5 .} 6 .}). start
Ii. yanlong
1. timertask task = new timertask () {2. public void run () {3. // execute the Task 4 .} 5 .}; 6. timer timer = new timer (); timer. schedule (task, delay );
3. Android Message Processing
New handler (). postdelayed (New runnable () {public void run () {// execute the task }}, delay );
The third type is recommended.