当前位置: 首页 > news >正文

CountDownTimer倒计时使用

CountDownTimer倒计时使用

    • CountDownTimer
    • 使用

CountDownTimer

代码片.

// An highlighted blockprivate MyCountDownTimer  timer;private final long TIME = 7 * 1000L;private final long INTERVAL = 1000L;private  class  MyCountDownTimer extends CountDownTimer{/*** @param millisInFuture    The number of millis in the future from the call*                          to {@link #start()} until the countdown is done and {@link #onFinish()}*                          is called.* @param countDownInterval The interval along the way to receive*                          {@link #onTick(long)} callbacks.*/public MyCountDownTimer(long millisInFuture, long countDownInterval) {super(millisInFuture, countDownInterval);}@Overridepublic void onTick(long millisUntilFinished) {long time = millisUntilFinished / 1000;Log.e("wuzhang",time+"秒");}@Overridepublic void onFinish() {cancelTimer();adsAPI.startAds(QRSuccessActivity.this, adRequest);finish();}}/*** 开始倒计时*/private void startTimer() {if (timer == null) {timer = new MyCountDownTimer(TIME, INTERVAL);}timer.start();}/*** 取消倒计时*/private void cancelTimer() {if (timer != null) {timer.cancel();timer = null;}}

使用

代码片.

@Overrideprotected void onCreate(Bundle savedInstanceState) {startTimer();.......
}@Overrideprotected void onDestroy() {super.onDestroy();cancelTimer();}
http://www.lryc.cn/news/221140.html

相关文章:

  • MySQL索引事务存储引擎
  • 【服务器使用】vscode winscp进行服务器容器连接(含修改初始密码)
  • Go和JavaScript结合使用:抓取网页中的图像链接
  • 通信协议---串口、RS232、RS485
  • UE5 c++将自定义UserWdiget添加到对应菜单栏
  • 三级缓存【又称提前暴露(early exposure)】
  • 【ARM Coresight 系列文章 3.5 - ARM Coresight -- JTAG-DP(JTAG Debug Port) 详细介绍】
  • 【笔记】回顾JavaWeb结合自身开发的项目——分层解耦与IOC、MySQL简单查询
  • Modelsim 使用教程(5)——Analyzing Waveforms
  • String-固长字符串序列
  • RABC权限模型与Spring Security
  • linux 编译lpthread
  • 工业自动化工厂PLC远程控制网关物联网应用
  • Nginx 实现负载均衡
  • 浅谈测试需求分析
  • 18、Python的编码规范:PEP 8介绍及基本遵循原则
  • AI:48-基于卷积神经网络的气象图像识别
  • AI:64-基于深度学习的口罩佩戴检测
  • Time series analysis of InSAR data: Methods and trends(NASA,2015)
  • 视频集中存储/云存储EasyCVR启动后查询端口是否被占用出错,该如何解决?
  • 【JMeter】后置处理器的分类以及场景介绍
  • 即时通讯技术文集(第22期):IM安全相关文章(Part1) [共13篇]
  • Node Sass version 9.0.0 is incompatible with ^4.0.0.
  • 【STL】:list的模拟实现
  • 第七章 图【数据结构与算法】【精致版】
  • 模型蒸馏学习
  • 总结Kibana DevTools如何操作elasticsearch的常用语句
  • 【QT】QT自定义C++类
  • 【多媒体文件格式】AVI、WAV、RIFF
  • AI创作系统ChatGPT商业运营系统源码+支持GPT4/支持ai绘画