Map went blank after rotation

2402
4
03-09-2012 10:59 AM
TigerLeung
New Contributor II
Hi guys,

I developed my first app with the Android API. Everything seems working as expected, except that the map goes blank after the device rotates. The error thrown in Eclipse is as follow:
03-09 15:52:46.363: E/libEGL(8091): call to OpenGL ES API with no current context (logged once per thread)

I didn't do anything special for handling the rotation. All map initialization is in OnCreate.

Any idea about how to fix the error or handle the rotation?

Thanks
0 Kudos
4 Replies
StephenQuan
Occasional Contributor
Did you remember to implement onPause() and onResume() as per the HelloWorldMap sample?
Neglecting to do so can cause the map control not play nice with the Android application life cycle.

 protected void onPause() {
  super.onPause();
  map.pause();
 }

 protected void onResume() {
  super.onResume();
  map.unpause();
 }
0 Kudos
EDWINSANCHEZ
New Contributor
I'm having this same issue. I have the "onPause" and "onResume" methods but my map is still being cleared after rotating the device. This is not good since doing so calls onCreate once again and my map loading process is a little too expensive to be repeating.
HELP!
0 Kudos
SimonKlein
Occasional Contributor
Hi,
have a look at this thread:
http://forums.arcgis.com/threads/52750-Rotation-changes-map-extent

As i stated there:

There is also the NOT recommended way of your activity just not acting on the rotation change.
Would look something like this.
<activity android:name="YourMapActivity" android:configChanges="keyboardHidden|orientation">

I'm doing the same in my app because of the loading expenses. Sometimes you have to work a little against the recommendations...
0 Kudos
IvanBespalov
Occasional Contributor III
Please explain me, what are you discussing about?

(1) Map Rotation or (2) device flipping (and map rotation as result of it)?

(1) - Clear - it works.

(2) - Need to write code around it 😄
onRetainNonConfigurationInstance()
NB! This method is deprecated.
public void onCreate(Bundle savedInstanceState) {
    // ...
    mapView = (MapView) findViewById(R.id.map);
    // ...
    Object[] init = (Object[]) getLastNonConfigurationInstance();
    if (init != null) {
      mapView.restoreState((String) init[0]);
      tiledMapServiceLayer = (ArcGISTiledMapServiceLayer) init[1];
      graphicsLayer = (GraphicsLayer) init[2];
    } else {
      mapView.setExtent(new Envelope(-85.61828847183895, 38.19242311866144, -85.53589100936443, 38.31361605305102));
      tiledMapServiceLayer = new ArcGISTiledMapServiceLayer(this, mapURL);
      graphicsLayer = new GraphicsLayer(this);
    }
    // ...
}
// ...
public Object onRetainNonConfigurationInstance() {
    Object appState = new Object[] { mapView.retainState(), tiledMapServiceLayer, graphicsLayer };
    mapView.removeAll();

    return appState;
}


setRetainInstance(boolean)
We has no time to try it ... So, when you solve problem paste your code.

Good luck.

P.S. This link (PDF) as bonus (contains link to WaterServiceApplication sample)
0 Kudos