title: Is there a way to check if my current wifi connected is different from previous connected wifi?
body: <p>I want to detect if my wifi connection has changed(if it has changed to cellular or some other wifi but not the same) after I return to the app from background. Is there any way to do this?
  I tried the below code but it doesn't work, it keeps firing up every single time i return to the app even if the same wifi  stays connected.</p>
  
  <pre><code> IntentFilter networkIntent = new IntentFilter();
          networkIntent.addAction("android.net.conn.CONNECTIVITY_CHANGE");
          networkIntent.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
          registerReceiver(wifichangereceiver, networkIntent);
  </code></pre>
  
  <p>Below is my receiver:</p>
  
  <pre><code>public final BroadcastReceiver wifichangereceiver = new BroadcastReceiver() {
  
  
          @Override
          public void onReceive(final Context context, final Intent intent) {
              final ConnectivityManager connMgr = (ConnectivityManager) context
                      .getSystemService(Context.CONNECTIVITY_SERVICE);
  
              final android.net.NetworkInfo wifi = connMgr
                      .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  
              if (wifi.isConnected()) {
                  hasWifiChanged = true;
                } else {
                  hasWifiChanged = false;
                }
  }
  </code></pre>