0

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!

dorien
  • 5,265
  • 10
  • 57
  • 116

3 Answers3

2

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!

Siggy
  • 752
  • 1
  • 5
  • 26
0

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

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
0

Add in your manifest:

 android:configChanges="orientation"
 android:screenOrientation="portrait"
baboo
  • 1,983
  • 17
  • 23
  • What does the orientation line do exactly? Do I also need to add it? – dorien Feb 22 '13 at 10:48
  • configChanges means that the configuration change is handled by the activity itself. Without it, the activity will be restarted if there is an orientation change. You might ask, if you've specified that the orientation is "portrait" how would it ever change? It can change if you launch another activity that alters the orientation, then that new activity exits, returning you back to your activity. For example, the default image capture intent on the Samsung Galaxy S3 does that in certain orientations. From: http://stackoverflow.com/questions/4885620/force-portrait-orientation-mode – baboo Feb 22 '13 at 11:06