bug: Android crashes when calling exitApp();
See original GitHub issueBug Report
Capacitor Version
š Capacitor Doctor š
Latest Dependencies:
@capacitor/cli: 2.4.0
@capacitor/core: 2.4.0
@capacitor/android: 2.4.0
@capacitor/electron: 2.4.0
@capacitor/ios: 2.4.0
Installed Dependencies:
@capacitor/ios not installed
@capacitor/cli 2.4.0
@capacitor/core 2.4.0
@capacitor/android 2.4.0
@capacitor/electron not installed
[success] Android looking great! š
Platform(s)
Android
Current Behavior
I wanted to implement the āclose app on native back buttonā feature.
When I call the exitApp()
method the app closes and crashes. The app is still in the list of apps running in the background, but when the user re-opens the app the splash screen is shown and the app boots freshly.
Debugger output:
Expected Behavior
Iād expect the app to not crash. It should pause in the background and resume when re-opened. (Just like it was with Cordova in the past).
Code Reproduction
if (!this.platform.is('android')) {
return;
}
this.platform.backButton.subscribeWithPriority(1, () => {
if (!this.routerOutlet.canGoBack()) {
App.exitApp();
}
});
Iāve also created a minimal demo app, which reproduces the issue: https://github.com/burningparrot/ionic-exit-app-crash-demo
Reproduction steps:
1.) clone the repo above
2.) ionic cap open android
3.) run the app in debug mode on a physical device
4.) push the deviceās native back button to close the app
5.) Carefully observe the debugger output on android studio
6.) re-open the app from the background
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Iāve tested on 3 different devices and I canāt reproduce the crash, and by the message it looks like a chrome bug, not a Capacitor bug.
App.exitApp();
kills the app activity, it does exactly the same as Cordovaāsnavigator.app.exitApp();
. After calling any of them the appās activity is killed, and if you open it again, it will reload the whole app, not resume it. It remains in ārecent itemsā, but that doesnāt mean itās backgrounded, recent items shows any app that was recently closed. If you donāt want the app to appear when it has been closed you can addandroid:autoRemoveFromRecents="true"
to theactivity
tag inAndroidManifest.xml
.Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.