【发布时间】:2016-04-04 12:41:21
【问题描述】:
我在导航抽屉中使用LogOut menuitem。一个应用的流程如下,
- 闪屏
- 登录活动
- ShopList 片段(Activity3 内部)
- MainActivity(这里我在 Navigation Drawer 中有 LogOut 菜单项)。
如果我按下 LogOut,我已经编写了导航 LogInActivity 的代码。
但它移动到 LogOut-->LogInActivity-->ShopList-->LogInActivity
LogOut代码如下,
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();
}
工作正常:(将 setFlags 更改为 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();
}
【问题讨论】:
-
有一个类似的问题here有答案。
标签: android navigation-drawer logout