新聞中心
IntervalTimer

成都創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為汕城等服務(wù)建站,汕城等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為汕城企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
java.lang.Object
|---ohos.utils.IntervalTimer
public abstract class IntervalTimer
extends Object為任務(wù)執(zhí)行提供一個(gè)計(jì)時(shí)器,該計(jì)時(shí)器持續(xù)一段時(shí)間并定期重復(fù)。
示例代碼:
new IntervalTimer(60000, 3000) {
@Override
public void onInterval(long remain) {
// This method will be called at the 3000th millisecond and repeatedly called every 3000 milliseconds.
}
@Override
public void onFinish() {
// This method will be called at the 60000th millisecond.
}
}.schedule();注意:IntervalTimer#onInterval(long) 是同步的。 如果此方法的執(zhí)行時(shí)間長(zhǎng)于間隔,則下一次調(diào)用將等待上一次回調(diào)完成。 例如,如果間隔為 3000 毫秒,并且 IntervalTimer#onInterval(long) 回調(diào)持續(xù) 4000 毫秒,則第一次調(diào)用在第 3000 毫秒,下一次調(diào)用在第 9000 毫秒。
構(gòu)造函數(shù)摘要
| 構(gòu)造函數(shù) | 描述 |
|---|---|
| IntervalTimer(long duration, long interval) | 創(chuàng)建具有給定工作持續(xù)時(shí)間和間隔的 IntervalTimer。 |
方法總結(jié)
| 修飾符和類型 | 方法 | 描述 |
|---|---|---|
| void | cancel() | 取消間隔計(jì)時(shí)器。 |
| abstract void | onFinish() | 當(dāng)間隔計(jì)時(shí)器的總工作持續(xù)時(shí)間結(jié)束時(shí)調(diào)用。 |
| abstract void | onInterval(long remain) | 每次間隔開始時(shí)調(diào)用。 |
| void | schedule() | 啟動(dòng)間隔計(jì)時(shí)器。 |
| 從類 java.lang.Object 繼承的方法 |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
構(gòu)造函數(shù)詳細(xì)信息
IntervalTimer
public IntervalTimer(long duration, long interval)
創(chuàng)建具有給定工作持續(xù)時(shí)間和間隔的 IntervalTimer。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| duration | 間隔定時(shí)器的工作時(shí)長(zhǎng),單位毫秒,不能小于interval。 當(dāng)工作時(shí)間結(jié)束時(shí),將調(diào)用 IntervalTimer#onFinish() 通知間隔計(jì)時(shí)器已關(guān)閉。 |
| interval | 間隔時(shí)間,單位毫秒,取值范圍為(1,duration]。每開始一個(gè)間隔,就會(huì)調(diào)用IntervalTimer#onInterval(long)來通知間隔定時(shí)器的剩余工作時(shí)間。 |
方法詳情
schedule
public final void schedule()
啟動(dòng)間隔計(jì)時(shí)器。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| IllegalArgumentException | 如果間隔小于或等于 0,或大于工作持續(xù)時(shí)間,則引發(fā)此異常。 |
cancel
public final void cancel()
取消間隔計(jì)時(shí)器。
onInterval
public abstract void onInterval(long remain)
每次間隔開始時(shí)調(diào)用。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| remain | 指示間隔定時(shí)器的剩余工作時(shí)間。 由于精度,該值可能重復(fù)。 |
onFinish
public abstract void onFinish()
當(dāng)間隔計(jì)時(shí)器的總工作持續(xù)時(shí)間結(jié)束時(shí)調(diào)用。
分享文章:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSIntervalTimer
本文地址:http://fisionsoft.com.cn/article/copchsj.html


咨詢
建站咨詢
