The app is in the background for a long time, prompting the user to log back in again

Source: Internet
Author: User

First step: When the app is in the background, call the timer's start () method to start the timer

In the baseswibackact of all activity inheritance
    public void OnStop () {
Eventbus.getdefault (). Unregister (this);
Onetimerfactory.gettimer (). Start ();
Super.onstop ();
}

Step two: When the user wakes up the app, the dialog box pops up

protected void OnStart () {
A is the flag that determines if login is invalid
if (APPDATAUTILS.A) {
Onetimerfactory.gettimer (). Cancel ();
Dialogunlock ();
APPDATAUTILS.A = false;
}
Super.onstart ();
}

The notation of a timer
  1. Private Countdowntimer timer = new Countdowntimer (10000, + ) {
  2. @Override
  3. public void OnTick (long millisuntilfinished) {
  4. Vertifyview.settext ((millisuntilfinished/ +) + "Second can be re-sent");
  5. }
  6. @Override
  7. public void OnFinish () {
  8. Vertifyview.setenabled (true);
  9. Vertifyview.settext ("Get Verification Code");
  10. }
  11. };

Countdowntimer timer = new Countdowntimer (10000, 1000), the first parameter represents the total time, and the second parameter represents the time interval. This means that the method Ontick is called back every second, and then the OnFinish method is recalled after 10 seconds.

The app is in the background for a long time, prompting the user to log back in again

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.