android 自定义CountDownTimer计时器(支持暂停)

本文介绍了一个自定义的Android CountDownTimer类,支持在计时过程中暂停和恢复。通过Handler消息机制实现计时,并提供了onTick和onFinish回调方法,方便在计时期间和结束时进行操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

废话不多说,直接上代码
package com.zdsoft.littleapple.utils.timer;

import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;

import com.zdsoft.littleapple.utils.log.LogUtils;

public abstract class CountDownTimer {

    /**
     * Millis since epoch when alarm should stop.
     */
    private final long mMillisInFuture;

    /**
     * The interval in millis that the user receives callbacks
     */
    private final long mCountdownInterval;

    private long mMillisFinished = 0;

    private long mElapsedRealtime;

    /**
     * boolean representing if the timer was cancelled
     */
    private boolean mCancelled = false;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish(long millisUntilFinished)}
     *                          is called.
     * @param countDownI
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值