private void fireConnectivityStatusChange() { // Since listeners may choose to remove themselves during their callback, we use a copy in the // for loop here. List<ConnectivityListener> listenersCopy = new ArrayList<ConnectivityListener>(connectivityListeners); for (ConnectivityListener listener : listenersCopy) { listener.onConnectivityStatusChange(this, connectivityStatus); } }
/** @see BroadcastReceiver#onReceive(Context, Intent) */ @Override public void onReceive(Context context, Intent intent) { boolean connected = isConnected(context); Timber.v("Connected: " + connected); // Loop over listeners for (ConnectivityListener listener : listeners) { listener.onNetworkStateChanged(connected); } }