Import {Component, viewchild} from ' @angular/core ';
Import {Platform, Toastcontroller, Nav, Ionicapp} from ' Ionic-angular ';
Import {StatusBar, splashscreen} from ' ionic-native '; Import {tabspage} from '.
/pages/tabs/tabs ';
@Component ({templateurl: ' app.html '}) Export class MyApp {rootpage = tabspage; Backbuttonpressed:boolean = false;
Used to determine whether the return key triggers a @ViewChild (' Mynav ') Nav:nav; Constructor (public Ionicapp:ionicapp, public platform:platform, public Toastctrl:toastcontroller) {Platform.ready
(). Then (() = {Statusbar.styledefault ();
Splashscreen.hide ();
This.registerbackbuttonaction ();//Register Return key event}); } registerbackbuttonaction () {this.platform.registerBackButtonAction () = {//If you want to click the Back button to hide toast or loadin G or overlay Add the following//This.ionicapp._toastportal.getactive () | | This.ionicapp._loadingportal.getactive () | | This.ionicapp._overlayportal.getactive () Let activeportal = This.ionicapp._modalportaL.getactive ();
if (activeportal) {Activeportal.dismiss (). catch (() = {});
Activeportal.ondiddismiss (() = {});
Return
} Let Activevc = This.nav.getActive ();
let tabs = ActiveVC.instance.tabs;
Let Activenav = tabs.getselected (); Return Activenav.cangoback ()?
Activenav.pop (): This.showexit ()}, 1); }//Double exit cue box Showexit () {if (this.backbuttonpressed) {//When the trigger flag is true, that is, 2 seconds to double-click the Back button to exit the app This.platform.exi
TAPP ();
} else {this.toastCtrl.create ({message: ' Press again to exit the app ', duration:2000, Position: ' Top '
}). present ();
This.backbuttonpressed = true; SetTimeout (() = This.backbuttonpressed = False, 2000);//2 seconds without a second click Back to mark the trigger flag as false}