CountDownTimer的使用
来源:互联网 发布:网络信息发布规定 编辑:程序博客网 时间:2024/06/06 07:39
CountDownTimer 是Google给提供的直接实现倒计时的类。使用方法
timer = new CountDownTimer(time,100) {//参数单位毫秒 @Override public void onTick(long arg0) { // TODO Auto-generated method stub countdown.setText("结束"+arg0/1000+(arg0%1000)/100);/精确到0.1秒的倒计时 time = arg0;//剩余的时间记下来 } @Override public void onFinish() { // TODO Auto-generated method stub countdown.setText("结束了"); } }; timer.start();
二、如果屏幕切换的时候保持继续倒计时状态。
定义key
private final static String key = "counttimekey";
保存剩余的时间
@Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub outState.putLong(key, time); super.onSaveInstanceState(outState); }
保存Timer对象
@Override@Deprecatedpublic Object onRetainNonConfigurationInstance() {// TODO Auto-generated method stubreturn timer;}
在onCreate方法中取消Timer,获得上次剩余时间
if(savedInstanceState!=null){ time = savedInstanceState.getLong(key); timer = (CountDownTimer) getLastNonConfigurationInstance(); timer.cancel(); }
0 0
- android CountDownTimer的使用
- CountDownTimer的使用
- 计时器countdownTimer的使用
- CountDownTimer的使用
- CountDownTimer的使用
- Android的 CountDownTimer的使用
- Android倒计时CountDownTimer的使用
- Android倒计时CountDownTimer的使用
- CountDownTimer倒计时器的使用
- CountDownTimer 倒计时器的使用
- CountDownTimer倒计时器的使用
- Android CountDownTimer类的使用
- 倒计时CountDownTimer 的是使用
- CountDownTimer手机短信计时器的使用
- android 倒计时CountDownTimer的使用
- CountDownTimer的使用和原理
- Timer和CountDownTimer的使用
- android中CountDownTimer的使用
- 浅析fresco
- UIImage部分拉伸——stretchableImageWithLeftCapWidth的使用
- php下使用ajax异步上传图片并显示缩略图
- 鸟哥的Linux私房菜(基础篇)- 第二十三章、软件安装: RPM, SRPM 与 YUM 功能
- Python 正则
- CountDownTimer的使用
- TrueCrypt的安装和使用
- Android适配之适配不同语言,即国际化
- [MSSQL]SQL Server 事务语法
- EJB,到底什么是EJB?
- (总结)try{}catch{}中有return,finally{}的执行情况
- IOS开发基础Object-C(07)—OC内存管理(1)-retain和release
- JDK动态代理实现原理--转载
- Encription