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.