angularjs - How to sync ionic navigation bar and hardware button in android in a phonegap mobile app -
in phonegap
app, there ionic navigation bar has button. if navigate app using navigation bar navigate each page, if use hardware button in point of time, navigation messed up. there fixes this.
<ion-view view-title="store locator" ng-controller="storelistctrl" > <ion-nav-buttons side="right"> <button form="searchid" class="button button-icon icon ion-ios7-search" ng-click="search(searchform.searchtext)"></button> </ion-nav-buttons> <ion-content> code here.... </ion-content> </ion-view>
this page in our app. button have overrided actions ioplatform.registerbackbuttonaction
$ionicplatform.registerbackbuttonaction(function (event) { if($state.current.name==="app.home"){ var mypopup = $ionicpopup.show({ title: 'exit application', scope: $scope, buttons: [ { text: 'cancel', ontap: function(e) { $state.go("app.home"); } }, { text: 'yes', type: 'button-positive', ontap: function(e) { navigator.app.exitapp(); } } ] }); } else if($state.current.name==="app.couponlists"){ $state.go('app.home'); } else if($state.current.name==="app.deallists"){ $state.go('app.home'); } else if($state.current.name==="app.coupondetail"){ $state.go('app.couponlists'); } else{ navigator.app.backhistory(); } }, 100);
go through docs first before implementing. ionic platform doc
options available
- onhardwarebackbutton(callback)
- offhardwarebackbutton(callback)
- registerbackbuttonaction(callback, priority, [actionid])
- on(type, callback)
make sure $ionicplatform.ready() called first.