Ion return button

I have a main Ionic app that I turned off the back button in the app, is there a reason the back button still works on my Android device?

I am currently testing from an ionic point of view.

here is my code:

.run(function($ionicPlatform) { $ionicPlatform.ready(function() { // 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(); } }); $ionicPlatform.registerBackButtonAction(function(e) { e.preventDefault(); }, 101); }) 
+5
source share
4 answers

According to ionic documentation

The action of the "Back" button cancels each of these actions whose priority is less than the priority that you provide.

And given that you want to completely disable the "Back" button in all situations and that the highest priority for actions in the link list is 500, you must specify a priority value of more than 500, 600, for example. The code below should work when placed in $ ionicPlatform.ready ()

  $ionicPlatform.registerBackButtonAction(function(e) {}, 600); 
+4
source

For those trying to sort this on Ionic 2:

http://www.codingandclimbing.co.uk/blog/ionic-2-android-back-button-13

and here is the actual post information:

In app.ts, do the following to return the back button (basically!):

  initializeApp() { this.platform.ready().then(() => { this.registerBackButtonListener(); }); } registerBackButtonListener() { document.addEventListener('backbutton', () => { var nav = this.getNav(); if (nav.canGoBack()) { nav.pop(); } else { this.confirmExitApp(nav); } }); } confirmExitApp(nav) { let confirm = Alert.create({ title: 'Confirm Exit', message: 'Really exit app?', buttons: [ { text: 'Cancel', handler: () => { console.log('Disagree clicked'); } }, { text: 'Exit', handler: () => { navigator.app.exitApp(); } } ] }); nav.present(confirm); } getNav() { return this.app.getComponent('nav'); } 

Note:

If you made a mistake in the fact that the application is not a property of the navigator :

1) Add the typing folder to the root directory of the application: for example. application / typing

2) Add a file named: pluginshackyhacky.d.ts

3) Add for properties required for TypeScript to compile .:

 interface /*PhoneGapNavigator extends*/ Navigator { app: any; } 

4) Add pluginshackyhacky.d.ts to the compilation in tsconfig.json :

  "files": [ "app/app.ts", "app/typings/pluginshackyhacky.d.ts", "app/typings/phonegap.d.ts" ] 

You can see that I also included the phonegap.d.ts file, which contains many missing properties / variables that allow TypeScript to compile without errors.

Hope this helps anyone who has this problem.

Greetings.

+3
source

Here is the solution for Ionic 2:

 constructor( public platform: Platform, //Platform controller public app: App, //App controller ) { platform.ready().then(() => { StatusBar.styleDefault(); Splashscreen.hide(); //Registration of push in Android and Windows Phone platform.registerBackButtonAction(() => { let nav = this.app.getActiveNav(); if (nav.canGoBack()){ //Can we go back? nav.pop(); }else{ this.platform.exitApp(); //Exit from app } }); }); } 
+1
source

Change the priority from 101 to 100 to override the default hardware functionality. If you have a priority of 100 already overriding functionality, you can override this override with priority of 101 if that makes sense.

 $ionicPlatform.registerBackButtonAction(function(e) { // android hardware back button was hit }, 100); 

Below is a list of all the priorities for the existing button buttons.

http://ionicframework.com/docs/api/service/$ionicPlatform/

-1
source

Source: https://habr.com/ru/post/1240383/


All Articles