Firebase在应用程序上注销后,“后退"按钮将带回到主页 [英] Back button will bring to home page after firebase logout on app
问题描述
My issue is very similar to this post: (When I press back button on login page it will go to main menu (after I select yes for logout in MainMenu activity)).
基本上,即使我选择是"选项注销后,它也确实使我回到缩进页面(登录"页面).但是,当我按实际电话(S7 Edge +)和2个仿真器(Nexus 4和Pixel 2 XL)上的后退"按钮时,它又带我回到了仪表盘页面,不是那样的.
Basically, even after I select "YES" option to logout, it does bring me back to the indented page (Login page). However, when I press the back button on my actual phone (S7 Edge+) and 2 emulators (Nexus 4 & Pixel 2 XL), it bring me to the dashboard page again which it should not be that way.
**我尝试过的是我在注销功能和菜单中添加了finish(),如下所示:
**WHAT I HAVE TRIED was I added finish() to Logout function and in the menu as seen below:
注销功能/方法
private void Logout(){
firebaseAuth.signOut();
finish();
startActivity(new Intent(SecondActivity.this, MainActivity.class));
finish();
}
菜单
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logoutMenu: {
final AlertDialog.Builder builder = new AlertDialog.Builder(SecondActivity.this);
builder.setMessage("Are you sure you want to logout?");
builder.setCancelable(true);
builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(SecondActivity.this, SecondActivity.class));
}
});
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(SecondActivity.this, "You are succesfully signed out!", Toast.LENGTH_LONG).show();
Logout();
finish();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
break;
}
case R.id.profileMenu: {
startActivity(new Intent(SecondActivity.this, UpdateProfileActivity.class));
break;
}
case R.id.passwordMenu: {
startActivity(new Intent(SecondActivity.this, UpdatePasswordActivity.class));
break;
}
}
return super.onOptionsItemSelected(item);
}
问题仍然存在.虽然在logcat中没有发现错误,所以我不确定如何解决此问题?
The issue still persist. There is no error found in logcat though so I am not sure how to overcome this issue?
有人可以解决吗?请指导我.
Does anyone have a solution? Please do guide me.
谢谢.
推荐答案
private void Logout(){
firebaseAuth.signOut();
Intent intent = new Intent(SecondActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finish();
}
**只需尝试一下**
**Just try this **
这篇关于Firebase在应用程序上注销后,“后退"按钮将带回到主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!