Home:ALL Converter>React-native: Why is app restarting when bluetooth headphones connected / disconnected? (Android)

React-native: Why is app restarting when bluetooth headphones connected / disconnected? (Android)

Ask Time:2022-12-01T19:29:28         Author:Darri

Json Formatter

My react native app (running on Android) is restarting whenever Bluetooth headphones are connected or disconnected. Why is this happening and how can I prevent it?

I'd expect the app to remain open when Bluetooth headphones are connected or disconnected, but instead the app restarts (the 'activity is recreated' in Android lingo).

I've tried altering the manifest by adding this line, but it didn't fix the issue:

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

A bit overkill, but I tried adding even more BT related permissions, which still didn't fix the issue:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

What am I missing?

Environment:

  • React-native: 0.66.2
  • Android OS: 12
  • Device: Pixel 4

Author:Darri,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74641170/react-native-why-is-app-restarting-when-bluetooth-headphones-connected-discon
yy