Skip to content

Commit

Permalink
Add checks to prevent re-initialization of the connectivitywatcher an…
Browse files Browse the repository at this point in the history
…d unregistering before registering the same watcher to prevent too manyrequests to networkcallback registeration (#387)
  • Loading branch information
gpanshu authored Apr 8, 2022
1 parent 17a7ce9 commit e7c4c3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ public AppSyncOfflineMutationManager(Context context,

//Setup Network Monitoring objects
this.networkUpdateHandler = new NetworkUpdateHandler(handlerThread.getLooper());
this.connectivityWatcher = new ConnectivityWatcher(context,
new NetworkInfoReceiver(this.networkUpdateHandler));
if (this.connectivityWatcher == null) {
this.connectivityWatcher = new ConnectivityWatcher(context,
new NetworkInfoReceiver(this.networkUpdateHandler));
} else {
this.connectivityWatcher.unregister();
}
this.connectivityWatcher.register();

//Setup ancillary stuff
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ public void onConnectivityChanged(boolean isNetworkConnected) {
if (isNetworkConnected) reportNetworkUp();
}
};
connectivityWatcher = new ConnectivityWatcher(applicationContext, callback);
if (connectivityWatcher == null) {
connectivityWatcher = new ConnectivityWatcher(applicationContext, callback);
} else {
connectivityWatcher.unregister();
}
connectivityWatcher.register();
}

Expand Down

0 comments on commit e7c4c3c

Please sign in to comment.