solinor/react-native-bluetooth-status

Receiver not registered

AmarnathGangapuram opened this issue ยท 4 comments

When Click on back button App always crashing in Android and its showing error as

"java.lang.IllegalArgumentException: Receiver not registered: com.solinor.bluetoothstatus.RNBluetoothManagerModule,
Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.solinor.bluetoothstatus."

So we need to registered broadcast receivers at onResume() only .

Can you please add below code in onHostResume method and update your library

    btAdapter = BluetoothAdapter.getDefaultAdapter();
    IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
    reactContext.registerReceiver(receiver, filter);

Thanks in advance

Thanks for noticing this - any chance you could make a PR for this yourself? This way you could get it fixed fast.

psyzz commented

Same issue for me :

02-20 18:58:11.911 18539 18539 E AndroidRuntime: FATAL EXCEPTION: main
02-20 18:58:11.911 18539 18539 E AndroidRuntime: Process: ng, PID: 18539
02-20 18:58:11.911 18539 18539 E AndroidRuntime: java.lang.RuntimeException: Unable to destroy activity {ng/ng.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: com.solinor.bluetoothstatus.RNBluetoothManagerModule$1@4e0dea4
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4497)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4516)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:39)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1817)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:193)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:6746)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.solinor.bluetoothstatus.RNBluetoothManagerModule$1@4e0dea4
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:1271)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1504)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:659)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:659)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.solinor.bluetoothstatus.RNBluetoothManagerModule.onHostDestroy(RNBluetoothManagerModule.java:120)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.bridge.ReactContext.onHostDestroy(ReactContext.java:254)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.moveToBeforeCreateLifecycleState(ReactInstanceManager.java:687)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:598)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.ReactInstanceManager.onHostDestroy(ReactInstanceManager.java:612)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.ReactDelegate.onHostDestroy(ReactDelegate.java:72)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.ReactActivityDelegate.onDestroy(ReactActivityDelegate.java:106)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at com.facebook.react.ReactActivity.onDestroy(ReactActivity.java:62)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.Activity.performDestroy(Activity.java:7403)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1307)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4482)
02-20 18:58:11.911 18539 18539 E AndroidRuntime: 	... 11 more

jmp commented

I've created a pull request in #52. I don't think fetching the Bluetooth adapter again is necessary, so I left that out and simply registered the broadcast listener again in onHostResume.

Please have a look and consider merging and releasing a new version with this fix.

๐ŸŽ‰ This issue has been resolved in version 1.5.0 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€