In My application i checked the internet connection before the application start If the connection is not available then it displayed a alert box with YES and NO button if the user click the No button of alert box then it close the application.
If the user click the Yes button of alert box then I start the an Activity by using the following code
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle("Info");
alertDialogBuilder.setMessage("Internet connection not available check ur internet connection");
alertDialogBuilder.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
context.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
dialog.cancel();
}
});
alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
System.exit(0);
return;
}
});
I want to check the user on the connection or not if the user on the internet connection then it will display the main Activity when the user press the Back Button otherwise Application Exited.