Scheduling tasks.
If you have a repetitive task in your Android app, you need to consider that activities and services can be terminated by the Android system to free up resources. Cancels this timer task. Performs an Android runtime-checked type conversion.Returns an integer hash code for this object.This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.The handle to the underlying Android instance.A constructor used when creating managed representations of JNI objects; called by the runtime.Returns a string containing a concise, human-readable description of thisobject.Compares this instance with the specified object and indicates if theyare equal.Returns the scheduled execution time.Invoked when the garbage collector has detected that this instance is no longer reachable. Schedule(TimerTask, Int64, Int64) Schedule(TimerTask, Int64, Int64)
Android中Timer是一个普通的类,其中有几个重要的方法;而TimerTask则是一个抽象类,其中含有一个抽象方法run()。 使用Timer类中的schedule()方法可以完成对TimerTask的调度,该方法具有三个参数,其函数声明如下:
schedule(TimerTask task, long delay, long period) 繰返用。delayミリ秒あとにperiodミリ秒間隔でタスク実行: scheduleAtFixedRate(TimerTask task, Date firstTime, long period) firstTime時間を基準としてperiodミリ秒単位でタスクを繰り返す: scheduleAtFixedRate(TimerTask task, long delay, long period)
However, the literature overwhelmingly recommends using Handler over TimerTask in Android (see here, here, here, here, here, and here).. If the task has been scheduled for one-time execution and has not yet run, or has not yet been scheduled, it will never run.
(If the task is running when this call occurs, the task will run to completion, but will never run again. 1.1. )This method is typically invoked from within a task's run method, to determine whether the current execution of the task is sufficiently timely to warrant performing the scheduled activity:The action to be performed by this timer task.Note that calling this method from within the run method of a repeating timer task absolutely guarantees that the timer task will not run again.This method may be called repeatedly; the second and subsequent calls have no effect.A task that can be scheduled for one-time or repeated execution by a Timer. The Java TimerTask and the Android Handler both allow you to schedule delayed and repeated tasks on background threads. Some of reported problems with TimerTask include: Can’t update the UI thread This tutorial describes how to schedule tasks in Android with the JobScheduler API. Handler is better than TimerTask.. Schedule(TimerTask, Int64) Schedule(TimerTask, Int64) Schedule a task for single execution after a specified delay. Schedule(TimerTask, Date, Int64) Schedule(TimerTask, Date, Int64) Schedule a task for repeated fixed-delay execution after a specific time has been reached. Android定时器Timer.schedule.