Ionic implementation double-click the return key to exit the software

Source: Internet
Author: User

1. First to install the Cordova plugin: plugin address: Cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git

2. Code in Run.js: (note the parameters to be added)

. Run (function ($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory, $cordovaToast) {
$ionicPlatform. Ready (function ($rootScope) {
Hide the Accessory Bar by default (remove this to show the accessory bar above the keyboard
for form inputs)
if (Window.cordova && window.cordova.plugins.Keyboard) {
Cordova.plugins.Keyboard.hideKeyboardAccessoryBar (TRUE);
}
if (window. StatusBar) {
Org.apache.cordova.statusbar Required
Statusbar.styledefault ();
}
});
Double-click Exit
$ionicPlatform. Registerbackbuttonaction (function (e) {
Double-click to exit when deciding which page to be in
if ($location. path () = = '/main) {
if ($rootScope. backbuttonpressedoncetoexit) {
Ionic. Platform.exitapp ();
} else {
$rootScope. Backbuttonpressedoncetoexit = true;
$cordovaToast. Showshorttop (' Press again to exit the system ');
SetTimeout (function () {
$rootScope. Backbuttonpressedoncetoexit = false;
}, 2000);
}
}
else if ($ionicHistory. Backview ()) {
$ionicHistory. GoBack ();
} else {
$rootScope. Backbuttonpressedoncetoexit = true;
$cordovaToast. Showshorttop (' Press again to exit the system ');
SetTimeout (function () {
$rootScope. Backbuttonpressedoncetoexit = false;
}, 2000);
}
E.preventdefault ();
return false;
}, 101);
})
But do not know why return to history this one is not implemented, because the development of software pages is not particularly much, so find a solution:
else if ($ionicHistory. Currentstatename () = = ' edit ') {

}
Determines whether the current state is an edit, and then returns to the first page ~
Reference article: Http://ionichina.com/topic/5514b539b6421f9166aa5f88

Ionic implementation double-click the return key to exit the software

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.