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
- Private Countdowntimer timer = new Countdowntimer (10000, + ) {
- @Override
- public void OnTick (long millisuntilfinished) {
- Vertifyview.settext ((millisuntilfinished/ +) + "Second can be re-sent");
- }
- @Override
- public void OnFinish () {
- Vertifyview.setenabled (true);
- Vertifyview.settext ("Get Verification Code");
- }
- };
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