Android - don't refresh Google Maps v2 on rotation

后端 未结 4 1516
礼貌的吻别
礼貌的吻别 2021-01-12 12:31

When I rotate my device, Google Maps v2 refreshes. How do I prevent this refresh from occurring? I\'m adding the map dynamically in a tab of a SherlockFragment.

4条回答
  •  灰色年华
    2021-01-12 13:26

    Emil's comment is right in explaining why the view of your map is being reset. Forbidding the orientation change via the manifest however is not good style.

    You need to retain the map fragment somehow or retain the fragment that contains the map fragment. After your 'host' activity has been recreated, you need to reattach the fragment to the activity instead of creating a new one. I don't have any code here but you'll find information about retaining fragments on the web.

    As an alternative you could save your maps state (foremost the camera position I guess) somewhere else and restore it after the fragment has been recreated.

提交回复
热议问题