I start an activity with startActivityForResult() but after the orientatikn changed and i return to the onActivityResult() method the requestCode not the same. I would like to use different layout if the screen orientation is in landscape mode. I tried in the manifest the configuration with orientation and screenSize params, but if i use this the layout not changed to the landscape layout. I started the activity with requestCode=0 but after the orientation changed i see that the requestCode = 66357 or something.
Asked
Active
Viewed 219 times
0
-
Are u using a fragment or a dialog? – makata Sep 16 '15 at 03:55
-
Just a simple Activity. – just Sep 16 '15 at 03:59
-
1When the orientation is changed, the activity is recreated. No longer the same! So, you need pass the requestCode on onPause() or on Destroy() via intent. – makata Sep 16 '15 at 04:16
-
maybe this http://stackoverflow.com/questions/5913130/dont-reload-application-when-orientation-changes – yelliver Sep 16 '15 at 04:34
3 Answers
0
Create two types of the layout folders. "layout-land" and "layout-port". put the required xml in both the directory with same name.

rKrishna
- 1,399
- 12
- 22
-
-
Declaring config changes in manifest is not required.you can keep one as default "layout" and other "layout-land". – rKrishna Sep 16 '15 at 03:46
-
But after the orientation changed and finish the activity it will return to the onActivityResult() method with a different requestCode. How should i handle this? – just Sep 16 '15 at 03:58
0
you can declare that your activity handles the configuration change itself, which prevents the system from restarting your activity.
In your AndriodMainfest.xml define configChanges
<activity android:name=".ResultActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
Then in your ResultActivity.java(that you call to get result) define onConfigurationChanged()
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
official link

Sanjeev
- 4,255
- 3
- 28
- 37
-1
You have two options:
A)Set your app to not rotate.
B)Or accept that the world is not perfect yet and modify your app to handle configuration change

Saulo Aires
- 76
- 5