Add check to broadcast receiver to prevent exception
Reviewed By: andreicoman11 Differential Revision: D2876479 fb-gh-sync-id: 55b7e31a91cf8a05849a0876bf912ac931233638
This commit is contained in:
parent
b7b27bdf25
commit
ca8792d2cc
|
@ -106,10 +106,14 @@ public class NetInfoModule extends ReactContextBaseJavaModule
|
|||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
getReactApplicationContext().registerReceiver(mConnectivityBroadcastReceiver, filter);
|
||||
mConnectivityBroadcastReceiver.setRegistered(true);
|
||||
}
|
||||
|
||||
private void unregisterReceiver() {
|
||||
getReactApplicationContext().unregisterReceiver(mConnectivityBroadcastReceiver);
|
||||
if (mConnectivityBroadcastReceiver.isRegistered()) {
|
||||
getReactApplicationContext().unregisterReceiver(mConnectivityBroadcastReceiver);
|
||||
mConnectivityBroadcastReceiver.setRegistered(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAndSendConnectionType() {
|
||||
|
@ -155,6 +159,17 @@ public class NetInfoModule extends ReactContextBaseJavaModule
|
|||
*/
|
||||
private class ConnectivityBroadcastReceiver extends BroadcastReceiver {
|
||||
|
||||
//TODO: Remove registered check when source of crash is found. t9846865
|
||||
private boolean isRegistered = false;
|
||||
|
||||
public void setRegistered(boolean registered) {
|
||||
isRegistered = registered;
|
||||
}
|
||||
|
||||
public boolean isRegistered() {
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
|
|
Loading…
Reference in New Issue