
ðąAndroid Studio Part 20 : DialogBox Exit App
#androidstudio #android
āļāļēāļĢāļŠāļĢāđāļēāļ DialogBox āļāļāļāļāļēāļāđāļāļ
1. āđāļāļāļĩāđāđāļĄāļāļđ Code āđāļĨāļ·āļāļ Override methods
2. āļāđāļāļŦāļē onBasePressed()āđāļĨāļ°āđāļāļīāđāļĄāļāļģāļŠāļąāđāļāļāļąāļāļāļąāļ§āļāļĒāđāļēāļ
== Code Example ==
@Override
public void onBackPressed() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Exit App");
alert.setMessage("Are you sure want to exit?");
alert.setCancelable(false);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog = alert.create();
alertDialog.show();
}