Tae-Sung Shin
Tae-Sung Shin

Reputation: 20643

App using libgdx restarts whenever device rotates

I made an app using accelerometer but problem is whenever it detects rotation of the screen, it goes to main menu.

I used following code to disable rotation but it still detects the rotation action and goes to mainmenu although it does not become landscape mode anymore.

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

How can I prevent this rotation detection?

Upvotes: 3

Views: 2702

Answers (3)

Vlad Yarovyi
Vlad Yarovyi

Reputation: 709

Kimi answer is correct, but if you want to run your game also on the Amazon device, then you should add the additional value "screenSize". So result would be:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

Upvotes: 2

Thomas
Thomas

Reputation: 181745

You will also want to add

android:configChanges="keyboard|keyboardHidden|orientation"

in order to prevent restarts when the keyboard appears or is hidden.

If you use this, you can even remove android:screenOrientation="portrait" if you want your game to work in both landscape and portrait mode. See the libgdx wiki: https://code.google.com/p/libgdx/wiki/ApplicationConfiguration#The_.xml_File

Upvotes: 2

Kimi
Kimi

Reputation: 6289

Put android:screenOrientation="portrait" inside your activity tag in the AndroidManifest.xml file. That attribute defines that this specific activity should always be run in the portrait mode and thus Android will not try to change screen orientation on rotation.

Upvotes: 7

Related Questions