title: Start another activity when detected network connection
body: <p>i am currently doing a project based on network connections.I am developing an app in which network connection is checked regularly.If there is no connection, a progress dialog should spin showing "No network connection" until the user himself turn the wifi on or any other kind of internet connection .After the wifi is turned on and if the app connects with wifi then the progress dialog should close and the control should pass to another activity. I have searched this in google for many times but didn't get a satisfactory answer. Below are my codes:</p>
  
  <pre><code>     public class Alert extends Activity implements Runnable{
  
  
          ProgressDialog pd;
       WifiManager wm,wifiManager;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState); 
          setContentView(R.layout.activity_alert);
  
  
          wm = (WifiManager) getSystemService(WIFI_SERVICE);
  
          if(!wm.isWifiEnabled()) {
          pd = ProgressDialog.show(this, "Network Error!!", "Network not found.Please make sure there is presence of any kind of network connection!!");
  
          Thread t = new Thread(this);
          t.start();  
          }
      }
  
      @Override
      protected void onResume() {
  
          super.onResume();
  
          if(wm.isWifiEnabled()) {
              pd.dismiss();
       Intent in=new Intent(Alert.this,WebPageView.class);
              startActivity(in);
  
          }
      }
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
  
              while(wm.getWifiState() != 3) {
  
                  try {
                      Thread.sleep(5000);
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  
              }
  
              }
      }
   }
  </code></pre>