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;
});
}
this.platform.ready().then(() => {
document.addEventListener('backbutton', () => {
console.log('backButton handler was called!');
}, false);
document.addEventListener('backbutton', () => {
console.log('backButton handler was called!');
}, true);
});
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