android:configChanges seems to be ignored
Asked Answered
G

1

6

I try to prevent that onCreate() is called when rotating the device. To reach this goal I followed the documentation and added

<activity android:name=".TabActivity"
          android:label="@string/app_name"
          android:configChanges="orientation">
     <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
</activity>

to the manifest. After that I inserted this to the Activity's source code:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

But it seems like Android ignores this method. A breakpoint which I set here is never reached.

What's my fault here? Is this a problem when using tabs?

Regards!

Giarla answered 30/8, 2011 at 8:1 Comment(2)
Your code looks OK. Did you try to set a breakpoint in your onCreate() to determine whether it is executed again (it should not as you said) when you switch your device's orientation?Bacchanal
Just see the post right below. Felix gave a good explanation.Giarla
C
5

Try this:

  android:configChanges="orientation|keyboardHidden"
Caine answered 30/8, 2011 at 8:6 Comment(2)
+1 that's the correct solution. If it doesn't work, try adding keyboard as well.Pahl
@J H because the emulator (and some devices) has a physical (emulated) keyboard. Thus, when you rotate it, it actually sends both keyboardHidden and orientation configuration changes, because it basically emulates popping the physical keyboard out.Pahl

© 2022 - 2024 — McMap. All rights reserved.