【问题标题】:How replace a fragment and save before fragment in android?如何在android中替换片段并在片段之前保存?
【发布时间】:2020-12-23 13:19:29
【问题描述】:

我在我的应用程序中使用了一些片段,当替换片段时, 在android中的片段调用destroyView方法之前,不要保存状态片段。 在导航组件中,我也搜索了它以使用替换片段。 什么是正确的解决方案?

【问题讨论】:

    标签: android android-fragments android-jetpack-navigation


    【解决方案1】:

    好吧,如果我解决了您的问题,那么您可以使用导航到另一个片段

    findNavController().navigate(R.id.destinationFragment)
    

    而不仅仅是替换片段

    并在 ViewModel 中保存您需要的所有信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      相关资源
      最近更新 更多