title: android communicate between activity and broadcast receiver
body: <p>I have an activity which displays some data fetched from the server. If no connection is available, activity displays some cached data; if connection is available, activity fetches data and displays it. It all works as expected.<br>
  Now, I would like to make my activity reload the data as soon as the connection occurs. I am using a simple Receiver that extends the BroadcastReceiver:  </p>
  
  <pre><code>public class ConnectionChangeReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          ConnectivityManager connectivityManager = (ConnectivityManager) context
                  .getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
          if (activeNetInfo != null) {
              //what to do here? 
          } 
       }
  }
  </code></pre>
  
  <p>Broadcast receiver is declared in my manifest file as follows:</p>
  
  <pre><code>&lt;receiver android:name=".ConnectionChangeReceiver"
            android:label="NetworkConnection"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.net.conn.CONNECTIVITY_CHANGE"/&gt;
          &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>In my activity, I register the receiver:</p>
  
  <blockquote>
    <p>ConnectionChangeReceiver receiver = new ConnectionChangeReceiver();
    this.registerReceiver(receiver,
                  new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));</p>
  </blockquote>
  
  <p>Now, I am confused as what to do next. When onReceive method is executed, how to make my activity aware of that? I know I could start a new activity, but that's not really what I want. Should I declare ConnectionChangeReceiver as a private class of my activity? Or is there any other solution?</p>