import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the Builder to create the AlertDialog
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this);
// Set the Properties
alertBuilder.setMessage("Do you want to exit from the application?");
alertBuilder.setCancelable(false);
alertBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MainActivity.this.finish();
}
});
alertBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// crate the AlertDialog
AlertDialog ald = alertBuilder.create();
// Display the AlertDialog
ald.show();
}
}