Android uses rxbinding and rxjava2 to realize the countdown function of SMS verification code

Scenario: when registering the account page, we click the button to send the verification code. When waiting for the verification code, the interface will give a countdown prompt. During this period, the button cannot be clicked. When the countdown is over, the button resumes.

It is not difficult to implement and function. This time, rxbinding and rxjava2 are used to implement it. It also realizes manual and automatic stop countdown to prevent multiple clicks.

Functional dynamic diagram

To use rxbinding and rxjava2, add the gradle configuration first:

First, bind and convert it into a countdown observable observer object through rxview. Clicks().

Sets the consumer observed object as a countdown prompt.

Subscribe to click events:

Stop the countdown, but you can still click again.

Destroy and empty data when exiting the current page.

Source code: various fancy implementations of countdown

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support 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
分享
二维码
< <上一篇
下一篇>>