ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.15k stars 1.01k forks source link

[Bug]: A change in active Bluetooth devices crashes app #7543

Closed Martijn0405 closed 1 month ago

Martijn0405 commented 4 months ago

Capacitor Version

6.0.0

Other API Details

npm --version output: 7.6.1
node --version output: v20.11.0

Platforms Affected

Current Behavior

I have a React, NextJS, and Capacitor app built and running on my Android device. When I pause the app by going to the home screen and then open the app again, nothing happens and the app gets resumed without restarting or crashing (as expected). But when I go to the home screen, connect a Bluetooth device, and then open the app, it gets destroyed, crashes, and restarts the app.

The Bluetooth device I am connecting is an iRig BlueTurn, which acts as a BlueTooth Low-Energy (BLE) keyboard.

Expected Behavior

The expected behavior would mean the app no longer crashes after a Bluetooth device gets connected or disconnected.

Project Reproduction

https://github.com/Martijn0405/ble-crash-frontend

Additional Information

Install the app by running npm i, then npm run app. Connecting a BLE device crashes the app, and immediately restarts it, which updates the time on the home page. image

ionitron-bot[bot] commented 3 months ago

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

jcesarmobile commented 3 months ago

Android restarts activities on configuration changes. Capacitor handles some cases, but looks like navigation is needed on some Android devices for not restarting the activity on bluetooth connection/disconnection.

I've updated your sample app with a fix, since the Capacitor fix will be on the android-template and won't have any effect on existing apps, only on newly created apps

https://github.com/Martijn0405/ble-crash-frontend/pull/1

ionitron-bot[bot] commented 1 week ago

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.