There are two ways to schedule a scheduled task in Android
1.schedule
2.scheduleAtFixedRate
The difference between the two methods is that the first call time (date when) this parameter
<span style= "FONT-FAMILY:SIMHEI;FONT-SIZE:14PX;" > //timertask task = new TimerTask () {@Overridepublic void Run () {//outputs the current millisecond in time log.i ("Test", ">>> "+ System.currenttimemillis ());}; Gets the current time of the millisecond for a long CRT = System.currenttimemillis (); Timer = new timer (); Schedule to current millisecond time minus 10 seconds// Timer.schedule (Task, New Date (CRT-10 *), +); Timer.scheduleatfixedrate (Task, New Date (CRT-10 *), $);</span>
The schedule dispatch does not calculate the first call time and it is called immediately after every 2 seconds.
The Scheduleatfixedrate Dispatch calculates the first call time, and since our first call time is set to the current time minus 10 seconds, the execution will first calculate the number of times the task should be executed within the 10 seconds, and then proceed at the set frequency.