开发者

How to avoid loading activity when screen orientation change in android

I am getting the value from webservice. I am displaying the progress dialog in activity. I am executing in portrait mode data is already loaded. when the user changes to landscape mode my acti开发者_运维百科vity loads again. How do I avoid that? I used an async task class in my activity.

Thanks


Add

android:configChanges="orientation|keyboardHidden"

in the activity declaration at the manifest.


You need to add

android:screenOrientation="portrait"

to the manifest file. (Or landscape if that is what you prefer)


I was having the same problem. I have just put in:

android:configChanges="orientation|keyboardHidden"

everywhere in my Manifest file and:

android:screenOrientation="portrait" in my main.xml.

It worked great. Here is the code parts.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:screenOrientation="portrait"
            android:layout_centerHorizontal="true"
    android:background="#7fffd4">

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.Addition"
  android:versionCode="1"
  android:versionName="1.0"
  android:configChanges="orientation|keyboardHidden">
  <uses-sdk android:minSdkVersion="8" />
  <supports-screens 
  android:smallScreens="true"
  android:normalScreens="true"
  android:largeScreens="true"
  android:resizeable="true"
  android:anyDensity="true"
  android:configChanges="orientation|keyboardHidden"/>
  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".main"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden">
             <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER"
             android:configChanges="orientation|keyboardHidden" />

</intent-filter>
    </activity>
    <activity android:name=".AdditionActivity"
              android:label="@string/app_name"
              android:configChanges="orientation|keyboardHidden" >
            <intent-filter>
            <action android:name="com.addition.INSTRUCTIONS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
  </application>
</manifest>

My big thanks you all you guys/girls who solves problems like the above.

Balbir 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜