Skip to content

Instantly share code, notes, and snippets.

@bangiqi
Created August 29, 2016 13:09
Show Gist options
  • Save bangiqi/1feb5df4ba4f1c171bbc87984ca79d0e to your computer and use it in GitHub Desktop.
Save bangiqi/1feb5df4ba4f1c171bbc87984ca79d0e to your computer and use it in GitHub Desktop.
//declare diatas method
//variable global
final Context context = this;
=================================================================
//simpan dalam method
// set title
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle("Perhatian!");
// set dialog message
alertDialogBuilder
.setMessage("Apakah anda ingin keluar dari aplikasi ini?")
.setCancelable(true)
.setNegativeButton("Batal", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//MenuActivity.this.finish();
dialog.dismiss();
}
})
.setPositiveButton("Keluar",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
finish();
System.exit(0);
//MainActivity.this.finish();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment