Android源码下载:验证码倒计时

移动开发 Android
Service+CountDownTimer+Handler完成倒计时功能,页面切换不中断。

功能分类:特效

支持平台:Android

运行环境:Eclipse

开发语言:Java

开发工具:Eclipse

源码大小:1.38MB

源码下载地址:http://down.51cto.com/data/1977282

源码简介

Service+CountDownTimer+Handler完成倒计时功能,页面切换不中断。

源码运行截图

运行效果

 

源码片段

  1. package com.zihao.timerdemo; 
  2.   
  3. import com.zihao.service.RegisterCodeTimerService; 
  4. import com.zihao.util.RegisterCodeTimer; 
  5. import android.os.Bundle; 
  6. import android.os.Handler; 
  7. import android.os.Message; 
  8. import android.view.View; 
  9. import android.view.View.OnClickListener; 
  10. import android.widget.Button; 
  11. import android.annotation.SuppressLint; 
  12. import android.app.Activity; 
  13. import android.content.Intent; 
  14.   
  15. /** 
  16.  * 主界面 
  17.  * 
  18.  * @author zihao 
  19.  * 
  20.  */ 
  21. public class MainActivity extends Activity { 
  22.   
  23.     private Button mGetCodeBtn;// 倒计时按钮 
  24.     private Intent mIntent; 
  25.   
  26.     @Override 
  27.     protected void onCreate(Bundle savedInstanceState) { 
  28.         super.onCreate(savedInstanceState); 
  29.         setContentView(R.layout.activity_main); 
  30.         initView(); 
  31.     } 
  32.   
  33.     /** 
  34.      * 初始化视图 
  35.      */ 
  36.     private void initView() { 
  37.         mGetCodeBtn = (Button) findViewById(R.id.get_code_btn); 
  38.         RegisterCodeTimerService.setHandler(mCodeHandler); 
  39.         mIntent = new Intent(MainActivity.this, RegisterCodeTimerService.class); 
  40.         mGetCodeBtn.setOnClickListener(new OnClickListener() { 
  41.   
  42.             @Override 
  43.             public void onClick(View v) { 
  44.                 // TODO Auto-generated method stub 
  45.                 mGetCodeBtn.setEnabled(false); 
  46.                 startService(mIntent); 
  47.             } 
  48.         }); 
  49.     } 
  50.   
  51.     /** 
  52.      * 倒计时Handler 
  53.      */ 
  54.     @SuppressLint("HandlerLeak"
  55.     Handler mCodeHandler = new Handler() { 
  56.         public void handleMessage(Message msg) { 
  57.             if (msg.what == RegisterCodeTimer.IN_RUNNING) {// 正在倒计时 
  58.                 mGetCodeBtn.setText(msg.obj.toString()); 
  59.             } else if (msg.what == RegisterCodeTimer.END_RUNNING) {// 完成倒计时 
  60.                 mGetCodeBtn.setEnabled(true); 
  61.                 mGetCodeBtn.setText(msg.obj.toString()); 
  62.             } 
  63.         }; 
  64.     }; 
  65.   
  66.     @Override 
  67.     protected void onDestroy() { 
  68.         // TODO Auto-generated method stub 
  69.         super.onDestroy(); 
  70.         stopService(mIntent); 
  71.     } 
  72.   

源码下载地址:http://down.51cto.com/data/1977282

责任编辑:闫佳明 来源: 网络整理
相关推荐

2015-03-23 17:58:04

验证码倒计时并行

2019-08-23 09:52:59

Axure 产品经理

2014-08-18 14:30:27

Android倒计时

2022-10-21 15:42:21

倒计时鸿蒙

2017-07-20 16:21:52

UICountDownTidelay

2013-10-10 09:23:15

Android 4.4Kitkat

2014-03-21 13:46:45

2011-04-11 09:17:28

Ubuntu倒计时

2014-02-18 10:36:33

2011-04-11 09:50:56

Ubuntu 11.0

2022-06-14 08:45:27

浏览器IEWindows

2013-10-08 09:24:39

Windows 8.1Windows 8

2020-10-28 17:54:49

成都信息安全

2013-04-09 10:01:18

微软Windows XP

2019-12-13 19:37:00

BashLinux命令

2023-08-16 11:23:59

2012-12-28 13:50:00

2012-03-28 09:37:07

Ubuntu 12.0倒计时

2013-06-06 11:27:52

iRadioWWDC2013
点赞
收藏

51CTO技术栈公众号