As the Android project, to use the real-time check the application launch, simply learn a timer
New a timer, then write a timertask subclass.
1 PackageComz.autoupdatefile; 2 3 ImportJava.util.Timer; 4 ImportJava.util.TimerTask; 5 6 Public classM {7 Public Static voidMain (string[] args) {8 //TODO todo.generated by Zoer9Timer timer =NewTimer (); TenTimer.schedule (NewMyTask (), 1000, 2000); One } A } - - classMyTaskextendsTimerTask { the - @Override - Public voidrun () { -System.out.println ("dddd"); + - } + A}View Code
In this way, you can start executing mytask after 1 seconds, once every two seconds.
Of course, the function of a timer can also be constructed by itself, and then by using sleep in the thread to simulate stopping for a period of time before performing an action.
In fact, look at the source of TimerTask can immediately know, TimerTask is to achieve the Runnable interface. In other words, a timer to perform an operation over a period of time is also done by a thread.
"So you can save yourself time writing threads."
Usage of the timer (Android learning note)