I am using LogOut menuitem in navigation drawer.The flow of an app is as follows,
- SplashScreen
- LogInActivity
- ShopList Fragment (Inside of Activity3)
- MainActivity (Here I am having LogOut menu item in Navigation Drawer).
If I press LogOut,I have written code to navigate LogInActivity.
But it moves to LogOut-->LogInActivity-->ShopList-->LogInActivity
LogOut Code is as follows,
if(id == R.id.nav_logout) {
commonUtil.dbUtil.open();
commonUtil.dbUtil.LogOut();
Intent moveToMain = new Intent(context, LogInActivity.class);
moveToMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
moveToMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
moveToMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(moveToMain);
MainActivity.this.finish();
}
Worked fine: (After changed setFlags to addFlags)
if (id == R.id.nav_logout) {
commonUtil.dbUtil.open();
commonUtil.dbUtil.LogOut();
Intent moveToMain = new Intent(context, LogInActivity.class);
moveToMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
moveToMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
moveToMain.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(moveToMain);
MainActivity.this.finish();
}