【问题标题】:Prevent existing Activity from flashing when changing Fragments?更改 Fragment 时防止现有 Activity 闪烁?
【发布时间】:2015-06-20 19:26:02
【问题描述】:

我遇到了一个问题,即在转换到低端设备上的另一个片段时,我的堆栈上的前一个片段显示。

假设我的堆栈上有三个片段; A、B 和 C。从片段 C 我开始片段 A,但我在片段 A 加载之前看到片段 B。除了使用似乎可以解决问题的转换之外,还有什么方法可以防止这种情况发生。

我想我希望有一些属性在这种情况下可能有用。以下是我进行片段转换的方式。

private void fragReplaceContentFragment(Fragment fragment, boolean withBackStack) {
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(contentFragmentContainer.getId(), fragment, String.valueOf(fragment.hashCode()));
    if (withBackStack) {
        transaction.addToBackStack(null);
    }
    transaction.commitAllowingStateLoss();
}

【问题讨论】:

    标签: android android-fragments commit


    【解决方案1】:

    尝试将transaction.commitAllowingStateLoss(); 替换为transaction.commit(); 并在此处提供反馈。

    【讨论】:

    • 如何解决问题?
    • 在提交期间允许状态丢失与问题有什么关系?
    • @SilentKnight,你的回答对我没有帮助。这并不能阻止我面临的问题。谢谢你的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    相关资源
    最近更新 更多