mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
Don't unregister the listener if it was never registered.
This commit is contained in:
parent
2cd3ebc7a8
commit
faa034a205
@ -69,6 +69,7 @@ public class NetworkManager extends Plugin {
|
|||||||
private static final String LOG_TAG = "NetworkManager";
|
private static final String LOG_TAG = "NetworkManager";
|
||||||
|
|
||||||
private String connectionCallbackId;
|
private String connectionCallbackId;
|
||||||
|
private boolean registered = false;
|
||||||
|
|
||||||
ConnectivityManager sockMan;
|
ConnectivityManager sockMan;
|
||||||
BroadcastReceiver receiver;
|
BroadcastReceiver receiver;
|
||||||
@ -103,6 +104,7 @@ public class NetworkManager extends Plugin {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
cordova.getActivity().registerReceiver(this.receiver, intentFilter);
|
cordova.getActivity().registerReceiver(this.receiver, intentFilter);
|
||||||
|
this.registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -144,9 +146,10 @@ public class NetworkManager extends Plugin {
|
|||||||
* Stop network receiver.
|
* Stop network receiver.
|
||||||
*/
|
*/
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (this.receiver != null) {
|
if (this.receiver != null && this.registered) {
|
||||||
try {
|
try {
|
||||||
this.cordova.getActivity().unregisterReceiver(this.receiver);
|
this.cordova.getActivity().unregisterReceiver(this.receiver);
|
||||||
|
this.registered = false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
|
Log.e(LOG_TAG, "Error unregistering network receiver: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user