I'm developing an app that makes requests to a web service more often. What I want to do is, when internet is not available or disconnected then instead of proceeding to request; app should show a message indicating unavailability of internet and kill itself. I've this code working fine with me - 

```
public GetXMLFromServer(Context context, GetXMLCallback gc,
          ArrayList<NameValuePair> params, String message) {
    this.context = context;
    this.gc = gc;
    this.postParameters = params;
    progressDialog = new ProgressDialog(this.context);
    this.message = message;
}

protected void onPreExecute() {
    progressDialog.setTitle("Please Wait");
    progressDialog.setMessage(message);
    progressDialog.show();
}

@Override
protected void onPostExecute(String result) {
    progressDialog.dismiss();
    gc.onSuccess(result);   
}

@Override
protected String doInBackground(String... params) {
    String response = null;     
    try{
        ConnectivityManager cm = (ConnectivityManager) this.context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {         
        } else if (netInfo == null) {
            AlertDialog alertDialog = new AlertDialog.Builder(this.context).create();
            alertDialog.setTitle("Connection Problem");
            alertDialog.setMessage("You are not connected to Internet");
            alertDialog.setButton("Exit",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {                                
                            isAvailable=false;
                            return;
                        }
                    });
            alertDialog.show();
        }

        /*if(isAvailable==false){
            then finish the calling activity or entire app.
        }*/
    }catch(Exception e){

    }
    try {
        response = CustomHttpClient.executeHttpPost(this.urlToFetch,
                this.postParameters);           
    } catch (Exception e) {
        e.printStackTrace();
    }
    return response;
}
  }`

```

Now my problem is, I can't figure out how to end entire app or calling activity before making a request and crashing the app because of there is unavailability of internet. (Commented part of code is where I want to stop app and end it)