Question

I have a list which contains images.I put a method every image which is open popup ( I mean I use android:theme="@android:style/Theme.Dialog" in manifest.xml) and when I click my image my new activity opens. For now evething works fine.

My first activity : I use this : setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

On my popup activity : I use this: setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

When I click image and open popup , yes the screen rotate and become lanscape and when I back button my screen rotate again and but the problem is : when I back my main activity and when roate again to portrait the list is reload again, I do not know why it is?

And is it possible to I do not want to rotate my first screen with the popup activity? thanks

Was it helpful?

Solution

Your list is reloading because the activity is destroyed and re-created when the orientation changes. The simplest thing is to manually handle orientation changes in the activity - and do nothing about it. Also, you can specify the portrait or landscape for an activity in the Manifest. Your manifest would then contain something like this:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:allowBackup="true"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="sensorPortait"
        android:configChanges="keyboardHidden|orientation"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".PreviewActivity"
        android:screenOrientation="sensorLandscape"
        android:label="@string/app_name"
        android:configChanges="keyboardHidden|orientation"
        android:theme="@android:style/Theme.Dialog"
        android:excludeFromRecents="true" >
    </activity>

    ...
</application>

Note the lines android:configChanges in the declaration of each activity. Also note the lines android:screenOrientation - with these lines added you don't need to call setRequestedOrientation in the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top