Consolidated list of Android hardware back button issues
See original GitHub issueDescribe the Bug This is a list of functionality that must work with the Android hardware back button. I want to try and keep a list of them in one place so we can finally verify the hardware back button works correctly as this has been problematic since v2.
The back button here refers to the hardware back button.
Web Browser
- Back button to navigate back to previous view.
- (https://github.com/ionic-team/ionic/issues/15422) If a modal is open, back button to close/dismiss the modal.
- If more than one modal is open at a time, back button should dismiss modals in the order they were opened (stack).
- If a popup is open, the back button should dismiss any popup.
- If a popup is open on top of a modal, the popup should be dismissed first on back button press.
- Pressing back in a tabbed application should navigate the user backward across tabs. (for example: Tab 1 -> Page 1 -> Page 2 -> Tab 2 -> Page 3 -> back -> Page 2 -> back -> Page 1) (similar issue: https://github.com/ionic-team/ionic/issues/18721)
- When side menu is open, back button should close the side menu before navigating.
Cordova/Capacitor
- (similar: #17689 #17984 #20713) When on the root page, pressing the back button should close the app (standard Android behaviour)
This will be possible in Ionic Framework v5.1. There will also be docs added that will show how to do this.
- (#19844) There should be an event that fires should the user want to show a confirmation popup before the back button closes the app.
This will be possible in Ionic Framework v5.1. There will also be docs added that will show how to do this.
Back button behaviour should be consistent between web and app (as per web list above)
Running in a Cordova/Capacitor app provides developers with additional tools to control the hardware back button functionality that does not exist in a web browser. For example, the
ionBackButton
event is only emitted in a Cordova/Capacitor app and is not emitted in a browser. As a result, hardware back button behavior when running in Cordova/Capacitor is currently not able to be perfectly aligned with the behavior when running that same app in a web browser; however, we will make the behavior as consistent as possible where appropriate.
- (https://github.com/ionic-team/ionic/issues/16505) If a native view is opened (i.e. Camera), pressing back button should dismiss native view back into the webview. (for example: Page 1 -> Page 2 -> Open camera -> back -> camera closed onto Page 2)
- https://github.com/ionic-team/ionic/issues/20559 When side menu is open, back button should close the side menu before navigating.
#17589 back button not working with ion-button and href to page
This is the expected behavior. The hardware back button works within the context of your application’s navigation stack. Using
href
is going to cause a full page reload, thus emptying the stack. Similarly, if you didnavController.navigateRoot
, you probably would not then want the app to navigate to the previous page when tapping the hardware back button. Developers should try and stay within the scope of their framework’s routing solutions (I.e. usingrouterLink
and related methods for Angular routing).
- #17824 subscribeWithPriority not working properly w/ popups & higher priority levels
Fixed in Ionic Framework v5.1
Expected Behavior Ultimately the user should not need to have to intervene with events, subscriptions or HostListener to handle back button navigation.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:87
- Comments:33 (4 by maintainers)
Top GitHub Comments
Hi everyone,
We are aware of these issues and are going to be looking into them now. We are currently prioritizing these issues and hope to have more updates to share soon.
We appreciate your patience as we work through these issues. Thanks!
We’ve also noticed that the hardware back button on Android behaves differently than the browser back button, especially when using
replaceUrl: true
andskipLocationChange: true
in Angular routing.