Black screen switching solution between Baidu map Fragment and fragment black screen
Many people who have used Baidu map are sad, and various bugs are unable to speak out. The most speechless phenomenon is the black screen phenomenon. For example, an Activity contains three Fragment, one of the Fragment nested MapView is used. When switching the three Fragment, there will be a clear black screen. This problem has occurred for a long time, and the SDK version exists very early, the latest SDK version still has this problem. The solution is as follows:
1. Manually call the onResume/onPause method of Fragment of MapView to set whether the view is visible, as shown below:
@ Override protected void OnPause () {mMapView. setVisibility (View. INVISIBLE); mMapView. onPause (); super. onPause ();} @ Override protected void onResume () {mMapView. setVisibility (View. VISIBLE); mMapView. onResume (); super. onResume ();}
2. Use a View to replace the Fragment with a nested MapView in the XML layout of the Activity. To display the Fragment, set the View to visible, and set it to invisible when not in use.
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/mapFrameLayout" android:layout_width="match_parent" android:layout_height="match_parent" > </FrameLayout> <FrameLayout android:id="@+id/otherFrameLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="invisible" > </FrameLayout> </FrameLayout>
3. Use the same nested Fragment object with MapView throughout the lifecycle of the Activity. You do not need to repeat the new instance. This is the most important thing.
Demo: http://download.csdn.net/detail/easyer2012/8968903
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.