code: public synchronized void startListening(Context context) {
          if (!mListening) {
              mContext = context;
  
              IntentFilter filter = new IntentFilter();
              filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
              context.registerReceiver(mReceiver, filter);
              mListening = true;
          }
      }
docs: This method starts listening for network connectivity state changes.
  
  @param context