Simple implementation example of verification code countdown in Android

preface

Many apps now use mobile phones to register. In order to confirm that they are using their own mobile phones, they will add a short-term verification code option. Recently, the company's projects use this SMS verification code, and the verification code countdown function should be added, that is, the verification code can be sent once in 60 seconds. It has been recorded again, and can be used at any time in the future.

realization

When sending a verification code, there is usually a button. After clicking, a verification code will be sent to the mobile phone you entered. I use a textview to display specific numbers. Only set the click event of textview;

There is a class in Android that can use this function conveniently, but there will also be a problem. At the last second, it will wait a long time before the text of "resend" will be displayed. This class is countdowntimer. Interested friends can study it and it is very convenient to use it, However, I later found that it was perfect to restart a thread to implement it.

The code is as follows:

explain:

Registerverificationcodetv is the textview that displays the countdown seconds. When using it, just call this method in the click event of registerverificationcodetv.

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>