无法保留嵌套片段 [英] Can't retain nested fragments

查看:261
本文介绍了无法保留嵌套片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有另一种保存嵌套片段状态的方法吗? 或者,如果我们不应该这样做,为什么呢?谢谢!

Is there another way of saving the state of the nested fragment ? Or if we shouldn't do this, why ? Thanks !

02-13 11:42:43.258: E/AndroidRuntime(7167): java.lang.IllegalStateException: Can't retain fragements that are nested in other fragments
02-13 11:42:43.258: E/AndroidRuntime(7167):     at android.support.v4.app.Fragment.setRetainInstance(Fragment.java:742)

推荐答案

您可以使用

You can use FragmentManager.saveFragmentInstanceState(Fragment) to retrieve a fragment state. The return value implements Parcelable, so you can put it in a Bundle.

对于恢复,您可以在使用

For restoration, you can provide the state after creating the fragment using Fragment.setInitialSavedState(Fragment.SavedState).

这篇关于无法保留嵌套片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆