I have a problem with MapFragment. The problem is the map works first time i open fragment, but when I leave it (I have sidebar menu) and come back - the screen is just white. But then if i rotate my phone the map shows up.
From debug I can see that this happens when I either enter first time or rotate, but it doesn't happen when I come back to fragment.
02-13 08:27:37.263: I/dalvikvm-heap(4553): Grow heap (frag case) to 23.106MB for 4194320-byte allocation
02-13 08:27:37.283: D/dalvikvm(4553): GC_FOR_ALLOC freed <1K, 18% free 23629K/28748K, paused 12ms, total 12ms
02-13 08:27:37.323: D/dalvikvm(4553): GC_FOR_ALLOC freed 4356K, 21% free 19534K/24648K, paused 13ms, total 13ms
Here is java code for fragment onCreateView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (rootView != null) {
Log.d("map","rootView != null");
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null)
Log.d("map","parent != null");
parent.removeView(rootView);
}
try {
Log.d("map","inside try");
rootView = inflater
.inflate(R.layout.fragment_map, container, false);
setupGmap();
} catch (InflateException e) {
Log.d("map","inside catch");
}
return rootView;
}
In XML:
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:name="pl.szymonmaslanka.qrapp.MapFragment" />
To add more clearness what happens:
Open app, click map in menu - map shows up correctly -> move to another menu item -> click again map menu - white screen istead of map -> rotate phone - map magically appears.
Cheers