Skip to content

Commit

Permalink
Merge pull request andreyvital#13 from adrian-tiberius/bug/issue#4
Browse files Browse the repository at this point in the history
fix multiple unregisterReceiver calls; fixes andreyvital#4
  • Loading branch information
CentaurWarchief authored Sep 26, 2016
2 parents 67f645c + be9c2f7 commit 5c633e3
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class SmsListenerModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private BroadcastReceiver mReceiver;
private boolean isReceiverRegistered = false;

public SmsListenerModule(ReactApplicationContext context) {
super(context);
Expand All @@ -27,7 +28,7 @@ private void registerReceiverIfNecessary(BroadcastReceiver receiver) {
receiver,
new IntentFilter(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)
);

isReceiverRegistered = true;
return;
}

Expand All @@ -36,12 +37,14 @@ private void registerReceiverIfNecessary(BroadcastReceiver receiver) {
receiver,
new IntentFilter("android.provider.Telephony.SMS_RECEIVED")
);
isReceiverRegistered = true;
}
}

private void unregisterReceiver(BroadcastReceiver receiver) {
if (getCurrentActivity() != null) {
if (isReceiverRegistered && getCurrentActivity() != null) {
getCurrentActivity().unregisterReceiver(receiver);
isReceiverRegistered = false;
}
}

Expand Down

0 comments on commit 5c633e3

Please sign in to comment.