gpt4 book ai didi

Android:Google Maps API v2 如何清理子 SupportMapFragment

转载 作者:行者123 更新时间:2023-11-30 03:29:31 26 4
gpt4 key购买 nike

我在 onCreate() 方法中使用 getChildFragmentManager() 以编程方式添加了一个 SupportMapFragment。

当我在 Activity 关闭后重新打开应用程序时,应用程序似乎正在渲染没有标记的旧子 SupportMapFragment。旧的子 fragment 也不可交互。

如何使用 SupportMapFragment 解决此生命周期问题?我是否需要调用特定的分离方法或类似的方法?

最佳答案

问题与我处理子 fragment 的方式有关。

每次父 fragment 调用 onCreate 时,子 fragment 都会被重新创建。

我做了以下处理我的 child fragment ,但可能有更好的方法:

private static final String TAG_FRAGMENT_MAP = "TagFragmentMap";

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ...
if (savedInstanceState == null) {
// create the fragments for the first time
ft.add(R.id.view_flip, new SupportMapFragment(), TAG_FRAGMENT_MAP);
ft.commit();
}
}

// ...

public void onViewStateRestored(Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
mMapFragment = (SupportMapFragment)findFragmentByTag(TAG_FRAGMENT_MAP);
}

关于Android:Google Maps API v2 如何清理子 SupportMapFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17692321/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com