Closed andreibursuc97 closed 3 years ago
Ok, so the fix is fairly simple, the genericReceiver
object needs to be made static, because if it is not static, at refresh, a new object (with no reference to the old one) will be created and the unregisterReceiver
method that is called before a new receiver is registered will consider that this new created object was not registered before so there is nothing to unregister.
Thanks @andreibursuc97 , I don't like static methods as a rule but the fix seems to work and I do not have a better solution... request you to please review https://github.com/darryncampbell/react-native-datawedge-intents/pull/11 before I merge to master and publish a new version of this plugin to npm. Thanks.
Resolved by https://github.com/darryncampbell/react-native-datawedge-intents/pull/11 and published as 0.1.3, https://www.npmjs.com/package/react-native-datawedge-intents/v/0.1.3
Looks like on app reload every time I call
registerBroadcastReceiver
a new receiver would be created and the old one will not be unregistered. So when I first open the app everything works as expected and I receive an intent per scan, but after I reload the app theregisterBroadcastReceiver
is called again and from now on I will receive two intents per scan. If I reload the app again I will receive three intents per scan and so on. Is there a way to unregister the receiver when the react component is destroyed so this problem won't appear anymore?