FileDocCategorySizeDatePackage
TimerTask.javaAPI DocAndroid 1.5 API3563Wed May 06 22:41:04 BST 2009java.util

TimerTask

public abstract class TimerTask extends Object implements Runnable
The {@code TimerTask} class represents a task to run at a specified time. The task may be run once or repeatedly.
see
Timer
see
java.lang.Object#wait(long)
since
Android 1.0

Fields Summary
final Object
lock
boolean
cancelled
long
when
long
period
boolean
fixedRate
private long
scheduledTime
Constructors Summary
protected TimerTask()
Creates a new {@code TimerTask}.

since
Android 1.0

        super();
    
Methods Summary
public booleancancel()
Cancels the {@code TimerTask} and removes it from the {@code Timer}'s queue. Generally, it returns {@code false} if the call did not prevent a {@code TimerTask} from running at least once. Subsequent calls have no effect.

return
{@code true} if the call prevented a scheduled execution from taking place, {@code false} otherwise.
since
Android 1.0

        synchronized (lock) {
            boolean willRun = !cancelled && when > 0;
            cancelled = true;
            return willRun;
        }
    
longgetWhen()


    /*
     * Method called from the Timer for synchronized getting of when field.
     */
      
        synchronized (lock) {
            return when;
        }
    
booleanisScheduled()

        synchronized (lock) {
            return when > 0 || scheduledTime > 0;
        }
    
public abstract voidrun()
The task to run should be specified in the implementation of the {@code run()} method.

since
Android 1.0

public longscheduledExecutionTime()
Returns the scheduled execution time. If the task execution is in progress it returns the execution time of the ongoing task. Tasks which have not yet run return an undefined value.

return
the most recent execution time.
since
Android 1.0

        synchronized (lock) {
            return scheduledTime;
        }
    
voidsetScheduledTime(long time)

        synchronized (lock) {
            scheduledTime = time;
        }