1. Requirements Description
Because you want to control when you return to the previous page, if you have a keyboard, you need to hide the keyboard, so you need to customize the physical return key Click event of the Android phone, you define the priority of the return button, and then implement the first page and the login page to double-exit the operation of the app.
2. Preparation
Add Plugin $cordovatoast, $cordovaKeyboard
Cordova Plugin Add Https://github.com/driftyco/ionic-plugins-keyboard.gitcordova plugin add https://github.com/ Eddyverbruggen/toast-phonegap-plugin.git
3. Code implementation
The introduction of $cordovatoast, $cordovaKeyboard dependence.
Angular.module (' starter ', [' Ionic ', ' route ', ' config ', ' global ', ' commonJs ', ' Ngcordova ']) .run ([' $ionicPlatform ', ' $rootScope ', ' $location ', ' $ Timeout ', ' $ionicHistory ', ' CommonJs ', ' $cordovaToast ', ' $cordovaKeyboard ', function ( $ionicPlatform, $rootScope, $location, $timeout, $ionicHistory, CommonJs, $cordovaToast, $ Cordovakeyboard) { $ionicPlatform. Ready (function () { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard if (window.cordova && window.cordova.plugins && Window.cordova.plugins.Keyboard) { Cordova.plugins.Keyboard.hideKeyboardAccessoryBar (True); } if (window. StatusBar) { // org.apache.cordova.statusbar required statusbar.stylelightcontent (); } }); //Physical return button control & double Exit app $ Ionicplatform.registerbackbuttonaction (function (e) { //to determine which page to double-exit if ($location. Path () == '/tab/todolist ' | | $location. Path () == '/tab/donelist ' | | $location. Path () == '/tab/account ' | | $location. Path () == '/login ') { if ($rootScope. Backbuttonpressedoncetoexit) { Ionic. Platform.exitapp (); } else { $rootScope .backbuttonpressedoncetoexit = true; $ Cordovatoast. Showshortbottom (' Press again to exit the system '); settimeout (function () { $rootScope .backbuttonpressedoncetoexit = false; }, 2000); } }else if ($ionicHistory. Backview ()) { if ($ Cordovakeyboard.isvisible ()) { $cordovaKeyboard. Close (); } else { $ionicHistory. GoBack (); } } else { $ rootscope.backbuttonpressedoncetoexit = true; $cordovaToast. Showshortbottom (' Press again to exit the system '); settimeout (function () { $ rootscope.backbuttonpressedoncetoexit = false; }, 2000); } e.preventdefault (); return false;      }, 101); }]);
Ionic series--android dual exit app and physical back button hide keyboard implementation