title: How to run code only once when internet connection is available again?
body: <p>I want to run some code only once when the User has internet access again.</p>
  
  <p>My first thought was using a BroadcastReceiver on "Android.net.conn.CONNECTIVITY_CHANGE" and unregister it right after the code was run. But I realized that this will also run the code when the user deactivates the internet connection. </p>
  
  <p>Is there a better way? Or is there a way to check if the current intent was a deactivation or an activation of the internet connection?</p>
  
  <p>This is how it looks currently:</p>
  
  <pre><code>final BroadcastReceiver OnConnecion = new BroadcastReceiver() {
                  @Override
                  public void onReceive(Context context, Intent intent) {
                      if(isOnline()){
                          vplan1 = new Vplan("vplan1", CheckService.this);
                          vplan2 = new Vplan("vplan2", CheckService.this);
                          Calendar heute = Calendar.getInstance();
                          Calendar date1 = vplan1.getCalendar();
                          Calendar date2 = vplan2.getCalendar();
                          if ((!(vergleiche(heute, date1) &lt; 0)) &amp; (!(vergleiche(heute, date2) &lt; 0))) {
                              getData task = new getData();               
                              task.execute();
                              unregisterReceiver(this);
                          }
  
                      }
                  }
              };
              registerReceiver(OnConnecion, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
  </code></pre>
  
  <p>Thanks</p>