android developer
android developer

Reputation: 116040

How to avoid activity re-creation when being rotated, while also respecting orientation lock?

Background

Each time the device is being rotated, Android will destroy the current activity and re-create it with the new configuration.

An easy way to avoid activity re-creation is by adding "configChanges" values to the manifest ("screenSize" and "orientation" as I recall).

The problem

If you use the "configChanges" attribute, the app won't respect the orientation lock feature that some (or all?) Android devices have, which prevent anything from being rotated when the screen is being rotated.

What I've tried

I tried playing with the "screenOrientation" attribute values, yet none of them achieved what I wanted.

The question

How can I prevent the activity from being re-created when the screen changes its orientation, while also respecting the user preference of orientation-lock?

Is it perhaps possible to get the value of this preference, so that I could let the activity lock its orientation when it's being set?

Upvotes: 2

Views: 490

Answers (1)

android developer
android developer

Reputation: 116040

OK, never mind. I think I just missed the correct one:

android:screenOrientation="user"

Together with the other configChanges values, this works perfectly.

Upvotes: 3

Related Questions