title: How to navigate to next activity by using AlertDialog?
body: <p>I am getting problem where to add intent and finish(); in alertdialog.</p>
  
  <p>Here when user has internet connection then a alert will popup and says <strong>You have internet connection</strong> in alertdialog box and when user <strong>click OK or Continue</strong> button then he must continue to next activity.
  If user have no internet connection then a alert will popup and says <strong>You don't have internet connection</strong> in alertdialog box and when user <strong>click Exit</strong> button application will close.</p>
  
  <p>Code in <strong>AndroidDetectInternetConnectionActivity.java</strong></p>
  
  <pre><code>package com.example.detectinternetconnection;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class AndroidDetectInternetConnectionActivity extends Activity {
  
  // flag for Internet connection status
  Boolean isInternetPresent = false;
  
  // Connection detector class
  ConnectionDetector cd;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      Button btnStatus = (Button) findViewById(R.id.btn_check);
  
      // creating connection detector class instance
      cd = new ConnectionDetector(getApplicationContext());
  
      /**
       * Check Internet status button click event
       * */
      btnStatus.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              // get Internet status
              isInternetPresent = cd.isConnectingToInternet();
  
              // check for Internet status
              if (isInternetPresent) {
                  // Internet Connection is Present
                  // make HTTP requests
                  showAlertDialog(AndroidDetectInternetConnectionActivity.this, "Internet Connection",
                          "You have internet connection", true);
  //Here user has to continue next activity
              } else {
                  // Internet connection is not present
                  // Ask user to connect to Internet
                  showAlertDialog(AndroidDetectInternetConnectionActivity.this, "No Internet Connection",
                          "You don't have internet connection.", false);
  //here application should close
              }
          }
  
      });
  
  }
  
  /**
   * Function to display simple Alert Dialog
   * @param context - application context
   * @param title - alert dialog title
   * @param message - alert message
   * @param status - success/failure (used to set icon)
   * */
  public void showAlertDialog(Context context, String title, String message, Boolean status) {
      AlertDialog alertDialog = new AlertDialog.Builder(context).create();
  
      // Setting Dialog Title
      alertDialog.setTitle(title);
  
      // Setting Dialog Message
      alertDialog.setMessage(message);
  
      // Setting alert dialog icon
      alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
  
  
      // Setting OK Button
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
          }
      });
  
      // Showing Alert Message
      alertDialog.show();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Code in <strong>ConnectionDetector,java</strong></p>
  
  <pre><code>package com.example.detectinternetconnection;
  
  import android.content.Context;
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  
  public class ConnectionDetector {
  
  private Context _context;
  
  public ConnectionDetector(Context context){
      this._context = context;
  }
  
  public boolean isConnectingToInternet(){
      ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) 
        {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) 
                for (int i = 0; i &lt; info.length; i++) 
                    if (info[i].getState() == NetworkInfo.State.CONNECTED)
                    {
                        return true;
                    }
  
        }
        return false;
  }
  }
  </code></pre>
  
  <p>So tell me where to put intent to proceed next activity and finish(); to close the application.</p>
  
  <p>Thank you...</p>