Saving MapFragment (Maps v2) State in Android

后端 未结 2 1423
北海茫月
北海茫月 2021-01-17 09:04

I\'m working with the new GoogleMaps API (v2) and have some problems with the fragment. I have two fragments in my app (Map, List) and the user can switch between them. Work

2条回答
  •  庸人自扰
    2021-01-17 09:30

    How can I accomplish this?

    If you replace() a fragment, the old fragment's views are destroyed, which takes out your MapView and, presumably, the CameraPosition.

    onSaveInstanceState() is mostly for configuration changes, such as screen rotations. MapFragment and SupportMapFragment already retain the CameraPosition (which, BTW, is Parcelable, so you can save the whole object in the Bundle rather than piecemeal).

    You could consider using show() and hide() instead of replace(), so the fragment and its views sticks around.

提交回复
热议问题