Android Handler's postDelayed () method usage, androidpostdelayed

Source: Internet
Author: User

Android Handler's postDelayed () method usage, androidpostdelayed
Is a function that allows you to create multi-threaded messages.
Usage:
1. First create a Handler object
Handler handler = new Handler ();
2. Create a Runnable object.
Runnable runnable = new Runnable (){
@ Override
Public void run (){
// TODO Auto-generated method stub
// The task to be done. Call this Runnable object again to implement the timer operation every two seconds.
Handler. postDelayed (this, 2000 );
}
};
3. Use the PostDelayed method to call this Runnable object two seconds later.
Handler. postDelayed (runnable, 2000 );
In fact, a 2 S timer is implemented.
4. If you want to disable the timer, you can do this.
Handler. removeCallbacks (runnable );

Of course, you can also try an alarm reminder delay function. For example, you can use MediaPlayer to play the alarm sound first,
If you don't remember it, after it is stopped, it will be played again in 5 minutes. If it is stopped again, it will be played in 4 minutes next time,
..................
You only need to change the delay time. It is easier to use a static object.

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.