I have tried to logout from my app when the user clicks on Logout.It is working fine in case the user after login without closing the app if he doed logout .Then it is worki
case R.id.drawer_item_logout: //name of logout button
AlertDialog.Builder builder=new AlertDialog.Builder(Home.this); //Home is name of the activity
builder.setMessage("Do you want to exit?");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
finish();
Intent i=new Intent();
i.putExtra("finish", true);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // To clean up all activities
//startActivity(i);
finish();
}
});
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
break;
![[1]](https://i.stack.imgur.com/ji95u.png)