question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: android back button not working on capacitor 3 with ionic.

See original GitHub issue

Bug 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

  1. Clone: https://github.com/RaphaelWoude/Example
  2. Run the following commands:
npm install
npm run build
npm run sync
npm run copy
npm run android
  1. Build with android studio.
  2. Start the app.
  3. Click on the test button.
  4. 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.

https://user-images.githubusercontent.com/47354694/110136780-610f6300-7dd0-11eb-896c-d305e8f65f05.mp4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
KirstenStakecommented, Jun 21, 2021

@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.

1reaction
RaphaelWoudecommented, Mar 8, 2021

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found