Download Android source code: Verification Code countdown

Source: Internet
Author: User

Download Android source code: Verification Code countdown

Function category: Special Effects

Supported platforms: Android

Runtime Environment: Eclipse

Development language: Java

Development tools: Eclipse

Source code size: 1.38 MB

Source code:Http://down.51cto.com/data/1977282

Source code Introduction

Service + CountDownTimer + Handler completes the countdown function, and page switching is not interrupted.

Source code running

Running Effect

 

Source code snippets

 
 
  1. Package com. zihao. timerdemo;
  2. Import com. zihao. service. RegisterCodeTimerService;
  3. Import com. zihao. util. RegisterCodeTimer;
  4. Import android. OS. Bundle;
  5. Import android. OS. Handler;
  6. Import android. OS. Message;
  7. Import android. view. View;
  8. Import android. view. View. OnClickListener;
  9. Import android. widget. Button;
  10. Import android. annotation. SuppressLint;
  11. Import android. app. Activity;
  12. Import android. content. Intent;
  13. /**
  14. * Main Interface
  15. *
  16. * @ Author zihao
  17. *
  18. */
  19. Public class MainActivity extends Activity {
  20. Private Button mGetCodeBtn; // countdown Button
  21. Private Intent mIntent;
  22. @ Override
  23. Protected void onCreate (Bundle savedInstanceState ){
  24. Super. onCreate (savedInstanceState );
  25. SetContentView (R. layout. activity_main );
  26. InitView ();
  27. }
  28. /**
  29. * Initialize the view.
  30. */
  31. Private void initView (){
  32. MGetCodeBtn = (Button) findViewById (R. id. get_code_btn );
  33. RegisterCodeTimerService. setHandler (mCodeHandler );
  34. MIntent = new Intent (MainActivity. this, RegisterCodeTimerService. class );
  35. MGetCodeBtn. setOnClickListener (new OnClickListener (){
  36. @ Override
  37. Public void onClick (View v ){
  38. // TODO Auto-generated method stub
  39. MGetCodeBtn. setEnabled (false );
  40. StartService (mIntent );
  41. }
  42. });
  43. }
  44. /**
  45. * Countdown Handler
  46. */
  47. @ SuppressLint ("HandlerLeak ")
  48. Handler mCodeHandler = new Handler (){
  49. Public void handleMessage (Message msg ){
  50. If (msg. what = RegisterCodeTimer. IN_RUNNING) {// countdown in progress
  51. MGetCodeBtn. setText (msg. obj. toString ());
  52. } Else if (msg. what = RegisterCodeTimer. END_RUNNING) {// countdown to completion
  53. MGetCodeBtn. setEnabled (true );
  54. MGetCodeBtn. setText (msg. obj. toString ());
  55. }
  56. };
  57. };
  58. @ Override
  59. Protected void onDestroy (){
  60. // TODO Auto-generated method stub
  61. Super. onDestroy ();
  62. StopService (mIntent );
  63. }
  64. }

Source code:Http://down.51cto.com/data/1977282

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.