Android - dialog sample
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomeActivity.this);
alertDialog.setTitle("Logout");
alertDialog.setMessage("Are you sure you want to Logout ?");
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent i = new Intent(HomeActivity.this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
Toast.makeText(HomeActivity.this,"Successfully Logged Out", Toast.LENGTH_LONG).show();
}
});
alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
});