I am making an app where the user can logout by clicking the logout button. Before logging out the user is in the Activty A, then he clicks on the ogout button in the navigation drawer and this takes him to the Activity B( Login screen activity). Now here if I click the back button the Activity A reappears even though I am clearing the activity stack by the following code,
Intent intent = new Intent(curr_context, Activity_B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
Also in the Activity B (login activity) I have the following code,
public void onBackPressed() {
if (backPressedToExitOnce) {
super.onBackPressed();
} else {
this.backPressedToExitOnce = true;
Toast.makeText(curr_context, "Press again to exit", Toast.LENGTH_LONG).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
backPressedToExitOnce = false;
}
}, 2000);
}
}
I am really clueless as to where am I wrong. Any help would be appreciated. Thanks in advance !!