bug: android back button not working on capacitor 3 with ionic.
See original GitHub issueBug Report
Capacitor Version
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 2.4.7
@capacitor/core: 2.4.7
@capacitor/android: 2.4.7
@capacitor/ios: 2.4.7
Installed Dependencies:
@capacitor/ios: not installed
@capacitor/cli: 3.0.0-beta.6
@capacitor/core: 3.0.0-beta.6
@capacitor/android: 3.0.0-beta.6
Platform(s)
Android
Current Behavior
The app closes when tapping the android back button instead of going back to the last route. In this case that’s the tab1 route.
Expected Behavior
The app should go to the last route when tapping the android back button. In this case that’s the tab1 route.
Code Reproduction
- Clone: https://github.com/RaphaelWoude/Example
- Run the following commands:
npm install
npm run build
npm run sync
npm run copy
npm run android
- Build with android studio.
- Start the app.
- Click on the test button.
- Press the hardware back button.
Other Technical Details
npm --version
output:
6.14.10
node --version
output:
v14.15.4
pod --version
output (iOS issues only):
Additional Context
I have provided a v2 version branch of the app in the same repository. This one does exactly what the app should do by going back to the last route. Here is also a video running on version 3 that shows that the ionic back button works but as soon as I tap the android back button it closes the app.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Backbutton event not fired - Capacitor - Ionic Forum
When I press the backbutton of my phone, the app is immediately closed; The events are not trigger. See examples : this.platform.ready().then(() ...
Read more >Ionic Capacitor hardware back button is automatically closing ...
I have noticed that back button runs properly in "@capacitor/core": "^2.4.7", but not in version 3.0.0 and I must use the latest version....
Read more >App Capacitor Plugin API
Force exit the app. This should only be used in conjunction with the backButton handler for Android to exit the app when navigation...
Read more >hardware back button event and confirm by the user to exit ...
In Capacitor 3 it may close the app directly by clicking the hardware back button. So we have to @capacitor/app dependency to fix...
Read more >Ionic: How to Simulate Android back button in Browser
When running in a Capacitor or Cordova application, Ionic Framework will emit an ionBackButton event when a user presses the hardware back ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ZXERSTON yes, what fixed it for me was installing the dependencies below (even if not referencing them directly in the app):
npm install @capacitor/app @capacitor/haptics @capacitor/keyboard @capacitor/status-bar
i had all of them already apart from @capacitor/app and as soon as I installed that one as well all was working again.
I have added
@capacitor/app
,@capacitor/haptics
and@capacitor/keyboard
to the app and the android back button is still broken. Am I missing something?