Embarking on my journey in ionic development, I delved into countless articles to learn the ropes. Despite my efforts, the real breakthrough came when I stumbled upon a discussion on Handling hardware back button in Ionic3 Vs Ionic4, seeking guidance from the experienced user @Fabian N. .
Alas, to my dismay, I encountered issues with the back button functionality on my device. The code simply refused to cooperate in my case. :(
For reference, here is my current Ionic setup:
Ionic:
Ionic CLI : 5.2.3 (/usr/local/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.6.2
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1
Cordova:
Cordova CLI : 9.0.0 (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="680b071a0c071e094504010a285146584659">[email protected]</a>)
Cordova Platforms : android 8.0.0, ios 5.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 16 other plugins)
Utility:
cordova-res : not installed
native-run : 0.2.8
System:
ios-deploy : 1.9.4
ios-sim : 8.0.1
NodeJS : v11.10.1 (/usr/local/bin/node)
npm : 6.7.0
OS : macOS Mojave
Xcode : Xcode 10.2 Build version 10E125
Despite implementing various event handlers in app.component.ts
, including different priorities, I still couldn't trigger an alert upon pressing the back button on Android device.
1. Test case
this.platform.backButton.subscribe(async () => {
alert("Fired Back Button");
});
2. Test case
this.platform.backButton.subscribe(() => {
alert("Fired Back Button");
});
3. test case
this.platform.backButton.subscribeWithPriority(0, () => {
alert("Fired Back Button");
});
4. test case
this.platform.backButton.subscribeWithPriority(100, () => {
alert("Fired Back Button");
});
Experimenting with different priorities, ranging from 100 to 999999, the alert still eludes me upon pressing the Android back button.
However, the natural behavior of the back button continues to navigate through pages effortlessly.
My ultimate goal is to effectively handle the Android hardware back button in my project. Any assistance would be greatly appreciated.
Thank you in advance for your support.