开发者

Background Activity for Map in Android started again if phone orientation is changed

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 d开发者_如何学JAVAisappear 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


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"


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜