Delay in running a task in Android

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.