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.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
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.
You can't, the map is getting refreshed because the
Activity
is getting re-created on configuration changes (screen rotations...). You could prevent the rotation of theActivity
by using:or
in the
Manifest
file under your mapActivity
.and this way prevent it from being recreated on rotations.
Sadly the way Google Handles map refreshing issue that you are seeing by
on the Activity tag in the Manifest in the Google maps application.
I fixed the problem by adding to the Activity in AndroidManifest.xml:
android:configChanges="orientation|screenSize"
Edit (04/28/2017) :
From the Android Documentation:
Maybe you could look at this answer, which properly saves the
SupportMapFragment
using theBundle
available in theonCreate
method ofFragmentActivity
.