Reputation: 543
My application is in Landscape mode .. I'm trying to change the Fragment in Portrait view ..
Used the below code to rotate from landscape to portrait ..
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
But the Fragment "onCreate" and "onCreateView" called twice ..
Can anyone please advice on implement Portrait View in Fragment class ? Or advice to how to avoid calling the onCreateView twice ?
Upvotes: 0
Views: 245
Reputation: 1719
In the Manifest file your activity should adds,
"android:configChanges="keyboardHidden|orientation|screenSize"
For example,
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Specifically you should add "screenSize" in the Android manifest file. So that your Fragment "onCreate" and "onCreateView" won't be called twice.
Upvotes: 1