我意识到这个问题之前已经被问过了,但之前的答案只帮我解决了一部分。情景如下:我们有一个仪表板片段(A),它会将用户引导到登录界面(B)。在成功登录后,他们会进入一个列表视图(C)。在返回按钮按下时,我想返回到A,因为用户不需要再次看到登录屏幕。另外,在成功登录后,我们将详细信息存储在共享首选项中,并在下次自动登录B,这一切都按计划进行。
我有以下FragmentHelper方法:
public static void goToNextFragement(Fragment fragment, int container, boolean addToBackStack, Fragment ctx)
{
// Create new fragment and transaction
FragmentTransaction transaction = ctx.getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(container, fragment);
if(addToBackStack)
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
在从B到C的事务中,我将addToBackStack布尔值设置为false,以便不调用transaction.addToBackStack(null);
。这再次很好地起作用,但问题发生在之后。
当用户在C上按返回并返回A时,我仍然可以看到A视图下充气的C视图。
任何帮助都将不胜感激。我希望我的图表有助于保持简单。