Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

Hardware back button handler not working in Android 11

$
0
0

I’m trying to prevent the back/exit function triggered by the default Android back button. For that I’m using Hardware Back Button, but it doesn’t work on Android 11 devices (SDK 30). When testing on other versions the override works as expected.

Function currently used:

constructor(private platform: Platform) {
	this.platform.backButton.subscribeWithPriority(9999, () => { // Tried to put absurd number for test
		console.log('Handler was called!');
	});
}

Other Failed Attempts:

1

@HostListener('document:ionBackButton', ['$event'])
private overrideHardwareBackAction($event: any) {
	$event.detail.register(100, () => {
		return;
	});				
}

2

this.platform.ready().then(() => {
	document.addEventListener('backbutton', () => {
		console.log('backButton handler was called!');
	}, false);

	document.addEventListener('backbutton', () => {
		console.log('backButton handler was called!');
	}, true);
});

3

ionViewDidEnter() {
	document.addEventListener("backbutton",function(e) {
	  // Do nothing
	}, false);
}

4 (Don’t make much sense here because uses ion-back-button)

import { IonBackButtonDelegate } from '@ionic/angular';

...

export class TestPage {

  @ViewChild(IonBackButtonDelegate, { static: false }) backButton: IonBackButtonDelegate;

  ...
  // Registering
  ionViewDidEnter() {
    console.log('ionViewDidEnter');
    this.setUIBackButtonAction();
  }

  setUIBackButtonAction() {
    this.backButton.onClick = () => {
      // handle custom action here
    };
  }
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>