【发布时间】:2012-04-01 12:58:58
【问题描述】:
来自 Android 开发参考:
public abstract boolean cancel (boolean mayInterruptIfRunning)
If the task has already started, then the mayInterruptIfRunning parameter
determines whether the thread executing this task should be interrupted in
an attempt to stop the task.
当谈到只发生一次的任务时,这对我来说很清楚。但不是,当我有一个周期性任务时,我想让它完成当前的“任务”,而不是开始一个新的。
对吗,我不能直接使用那些开箱即用的东西?我认为如果我将参数设置为 true,它可以在当前任务完成之前停止它,如果我将其更改为 false,并且当前有一个任务正在运行,它什么也不做。是这样吗?
我将如何实现我想要的?我是否应该以某种方式轮询任务以查找它是否正在运行,并在发现它没有运行时取消它?
【问题讨论】: