0

When ever i change in to another orientation the Activity onCreate() method is called again? how ever i used android:configChanges="orientation|keyboardHidden" but it prevent to change another orientation.how to block on calling the OnCreate() again?

Thanks in advance...

Kakey
  • 3,936
  • 5
  • 29
  • 45
  • How do you propose android should handle orientation changes if it didn't destroy itself and rebuild? – Falmarri Nov 09 '10 at 17:41

2 Answers2

3

Whenever the orientation changes, the application starts over in the onResume() method.

If you do not want it to change orientation when the user flips the phone, you need to set this in your manifest file:

<activity android:name="YourActivity"
android:screenOrientation="portrait" />

Or landscape if you wish.

If you do want your application to continue where it left of before the user changed orientation on the phone and you do want your application to change orientation too, you need to keep track of the state of the application and set these values in your onResume()-method.

Eric Nordvik
  • 14,656
  • 8
  • 42
  • 50
0

This is a little dirty, but you could simply set a flag-style boolean for the activity. First time through, set the "already ran onCreate" flag to true and use that to avoid running the code multiple times.

Not very proper, but should work.

bhekman
  • 3,227
  • 21
  • 24