Ionic version:
[x] 5.1
Current behavior:
On Android, pressing the back button on the first page of a project always causes the app to close.
This happens absolutely even if the control of the back button is overridden so as not to quit the application according to the following Hardware Back Button.
However, once you have moved to another screen, the app will not exit even if you go back to the first page and press the back button.
https://github.com/ionic-team/ionic-docs/blob/master/src/pages/developing/hardware-back-button.md
Expected behavior:
Even if the screen transition is not performed, the overwriting process of Hardware Back Button is executed and the application is not terminated.
Steps to reproduce:
Related code:
I've pushed a sample below.
https://github.com/masatada-kurihara/ionic-back-button-test
The overwriting process of the back button is described in the NgOninit of HomePage, but the moment I start the application, the process is not executed.
After the transition to FugaPage, the back button overwriting process is enabled.
Other information:
Probably not occurring in ionic4.8.1.
Ionic info:
Ionic:
Ionic CLI : 6.8.0 (/Users/masatada.kurihara/.nvm/versions/node/v12.9.1/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.1.0
@angular-devkit/build-angular : 0.803.26
@angular-devkit/schematics : 8.3.26
@angular/cli : 8.3.26
@ionic/angular-toolkit : 2.2.0
Cordova:
Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : not available
Cordova Plugins : not available
Utility:
cordova-res : not installed
native-run (update available: 1.0.0) : 0.2.8
System:
Android SDK Tools : 26.1.1 (/Users/masatada.kurihara/Library/Android/sdk)
ios-deploy : 1.9.4
NodeJS : v12.9.1 (/Users/masatada.kurihara/.nvm/versions/node/v12.9.1/bin/node)
npm : 6.13.7
OS : macOS Catalina
Xcode : Xcode 11.4.1 Build version 11E503a
Thanks for the issue. I am going to close this as this is not a bug in Ionic Framework.
Ionic Framework does not terminate the application for you automatically. This is something the developer needs to add to their application. If the application is quitting even if you have not added any code to do so, then the source of the issue is likely coming from somewhere else. I tested this in a Capacitor application, and the application does not quit when pressing the hardware back button (as expected).
Please see https://ionicframework.com/docs/developing/hardware-back-button#exiting-the-app for examples on how to exit the application. Thanks!
@liamdebeasi
Do not close the ticket.
Even if you override the hardware button processing according to that documentation, Cordova will still close the app.
A sample is provided below. Please execute ionic cordova run android.
https://github.com/masatada-kurihara/ionic-back-button-test
I am not able to reproduce that behavior using the reproduction you provided. When pressing the hardware back button on the root page, Cordova did not exit the application.
Can you provide an example of Cordova closing the application when pressing the back button in an Ionic app?
@liamdebeasi
Thanks for trying it out.
It seems to be occurring only on Android 9.x devices. I'll look into it a bit more.
@liamdebeasi
I tried the same behavior on the same app, on Android 8.
Problem not occurred.
There may be problems with Android 9.x and above.
@liamdebeasi
I tried it on several devices.This seems to happen on Android 9.0 and later.
I feel like this is a Cordova/Capacitor issue (or interface on ionic issue), do you have any knowledge on this?
[] 7.0 (nexus7)
[] 8.0 (Zenfone4)
[x] 9.0 (pixel2)
[x] 9.1 (galaxy s9)
[x] 10.0 (pixel3)
@toshiya-sato
Thanks for the supplement.
Thanks for the follow up. I tried your application on a Pixel 3 running Android 9 and a Pixel XL Running Android 10 with Capacitor and Cordova.
I was unable to reproduce this behavior on any device running Capacitor, but I was able to reproduce this behavior on Android 9+ only when using Cordova. This sounds like a Cordova bug, so I would recommend you file an issue with the project maintainers. Thanks!
@liamdebeasi
It was a problem with the cordova-plugin-splashscreen.
https://github.com/apache/cordova-plugin-splashscreen/issues/186
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 Ionic, please create a new issue and ensure the template is fully filled out.