0

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.

just
  • 1,900
  • 4
  • 25
  • 46

3 Answers3

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
  • I did it, but i didnt see that the land layout was selected. – just Sep 16 '15 at 03:40
  • 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