Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is my fix to the first problem:</p> <p>It seems that <code>Map</code> is trying to unparcel all the bundle, not just it's own information when I call <code>mMap.onCreate(savedInstanceState)</code> and it has problem with it if I'm using my custom <code>Parcelable</code> class. The solution that worked for me was removing my extras from <code>savedInstanceState</code> as soon as I used them - before I call Map's <code>onCreate()</code>. I do it with <code>savedInstanceState.remove(MY_KEY)</code>. Another thing I had to do was to call <code>mMap.onSaveInstanceState()</code> before adding my own information to <code>outState</code> in <code>Fragment's</code> <code>onSaveInstanceState(Bundle outState)</code> function.</p> <p>And here's how I handled the second one:</p> <p>I simplified the example project to the bare bones. I was adding raw <code>Markers</code> to the map and if I replace the <code>Fragment</code> with map with another one then after clicking "back" I still got "nulled" map. So I did two things:</p> <ol> <li>saving <code>CameraPosition</code> in <code>onPause()</code> function to restore it in <code>onResume()</code></li> <li>setting <code>mMap</code> to null in <code>onPause()</code> so when the <code>Fragment</code> comes back, the <code>Markers</code> are added again by the <code>addMapPoints()</code> function (I had to change it a little bit since I was saving and checking <code>Markers</code> id's).</li> </ol> <p>Here are code samples:</p> <pre><code>private CameraPosition cp; </code></pre> <p>...</p> <pre><code>public void onPause() { mMapView.onPause(); super.onPause(); cp = mMap.getCameraPosition(); mMap = null; } </code></pre> <p>...</p> <pre><code>public void onResume() { super.onResume(); setUpMapIfNeeded(); mMapView.onResume(); if (cp != null) { mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cp)); cp = null; } } </code></pre> <p>And to update the camera position in <code>onResume()</code> I had to manually initialize maps. I did it in <code>setUpMap()</code>:</p> <pre><code>private void setUpMap() { try { MapsInitializer.initialize(getActivity()); } catch (GooglePlayServicesNotAvailableException e) { } mMap.setOnInfoWindowClickListener(this); mMap.setOnMapLongClickListener(this); addMapPoints(); } </code></pre> <p>I realize that those aren't real solutions - just overrides but it's the best I can do for now and the project must go on. If anyone finds cleaner fixes I'll be grateful for letting me know about them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload