dorien
dorien

Reputation: 5407

Android lock screen orientation and leaving onCreate() untouched

I am running something in onCreate() upon initialisation.

If a user rotates the screen, it recalls onCreate().

I want to disable screen rotation and let onCreate() run ONLY upon the initial initialisation.

Is it enough to add android:screenOrientation="portrait" to the manifest or will onCreate() still be run?

Thanks!

Upvotes: 0

Views: 923

Answers (3)

baboo
baboo

Reputation: 2023

Add in your manifest:

 android:configChanges="orientation"
 android:screenOrientation="portrait"

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157457

If you hold your Activity in Portrait or in Landscape, the rotation will no longer happens. So the onCreate() will run to the end though you will try to rotate your device

Upvotes: 0

Siggy
Siggy

Reputation: 752

If you put android:screenOrientation="portrait" in your Manifest the Phone doesnt handle orientation changes and onCreate() doesn't get called again. So: YES it is enough!

You can easily check it if you set a Debug-Marker in your onCreate() and then rotate your phone!

Upvotes: 2

Related Questions