0

I need help.

My app still fails when the device orientation changes to landscape.

Whats the problem?

I have set in the Android manifest android:configChanges="keyboardHidden|orientation" and in the main Activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    setContentView(R.layout.main);
    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();
    }
}

and my activities are fragments.

bool.dev
  • 16,879
  • 5
  • 62
  • 90
Ares
  • 31
  • 1
  • 1
  • 8

2 Answers2

1

Improper onConfigurationChanged().

Remove setContentView(R.layout.main); from onConfigurationChanged().

David Manpearl
  • 11,858
  • 8
  • 50
  • 69
  • We must know how the app fails? If the failure is a force close or other `Exception`, then you must show the stacktrace LogCat. If the LogCat shows an `Exception` caused in a line of your code, it will show the line number in one of your Java files. If possible, please show us that line of source code. – David Manpearl Mar 27 '13 at 20:14
  • I had to change manifest and main activity dont rotation, but other activity working correctly – Ares Mar 28 '13 at 07:38
  • I'm glad you solved your problem. These things can be complicated. – David Manpearl Mar 28 '13 at 07:40
0

Probably you are having the problem when your activity is being recreated.

Perhaps the solution might be here

Community
  • 1
  • 1
Nakayama
  • 161
  • 2
  • 10