views:

106

answers:

2

Hi,

i've developed an android app that's fetches an xml file and displays this data via several markers on the map. This works fine so far.

The problem right now is that when i switch the orientation of the phone (portrait->landscape or vice versa) the markers disappear for a small moment, the xml processing is started again and then they reappear.

Is there a way to prevent this re-loading of the file? It only takes about 2-3 seconds..so no big deal, but still disturbing

+2  A: 

Have you tried to override OnConfigurationChanged() method in your activity? if not then try below snippet

@Override
public abstract void onConfigurationChanged (Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//Do nothing here
}

also in your manifest file, add following attribute to your activity

android:configChanges="orientation"
Vishwanath
This has always worked for me, but I would point out the top snippet isn't required, because it does nothing.
Jim Blackler
A: 

You can force the layout to be only Horizontal or Vertical and avoid the reload on layout change with this:

this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

this refers to the Activity.

YaW