Can some one please give the explanation. I tried to analyze a lot. but no luck. Following is the situation what are the methods will invoke when i changed the mode of device to land scape to portrait while running my application?
-
1OnStart and OnResume are called, not OnCreate. Check [Here][1]. [1]: http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android – While-E Aug 04 '12 at 18:07
-
Search in Google for Android activity methods on Android returns up: http://developer.android.com/reference/android/app/Activity.html as the first result. – Sagar Hatekar Aug 04 '12 at 18:18
-
@While-E : Incorrect. An `Activity` is destroyed and re-created as part of a configuration change (such as rotation) which means that `onCreate(...)` WILL be called. Also please note, the method names you mention in your comment are `onStart`, `onResume` and `onCreate`...they don't start with a capital `O`. – Squonk Aug 05 '12 at 03:43
-
@Squonk Apologies for the capital letter, I was just getting the point across. As far as the onCreate not being called on configuration change I simply quoted the answer that was marked correct with 256 up-votes.... which turns out was extending "Application" class and not "Activity"... and in his question it does say "application" not "activity" – While-E Aug 05 '12 at 14:16
-
1@While-E : Regardless of how you interpret the OP's question, your first comment is misleading. Firstly the `Application` class isn't affected by change in orientation and the question you link to is about avoiding re-initialising various aspects of an `Activity`. The accepted answer recommends using `Application` to maintain global-state. Secondly, the OP's question here is about the "methods invoked on changing device orientation". If the OP means `Application`, the answer is NONE. If the OP meant `Activity` your comment of "onStart and onResume are called, not onCreate." is incorrect. – Squonk Aug 05 '12 at 22:22
2 Answers
Your Activity is literally getting destroyed and recreated. Check out the Activity LifeCycle
Assuming your Activity is running you will go though.
- onPause()
- onStop()
- onDestory()
- onCreate()
- onStart()
- onResume()
In addition, you will also get onSaveInstanceState and onRestoreInstanceState called. This is where you can save off anything in the your Activity that you want restored, like cursor position, view focus, etc...
I agree with @While-E check out this post. Has a lot of good information Activity restart on rotation Android

- 1
- 1

- 8,511
- 4
- 43
- 64
-
1@FrankSposaro : Sorry for the down-vote but you posted contradictory information. It is correct that the `Activity` will be destroyed and recreated but you missed out `onDestroy()` and `onCreate(...)` in your bullet points. – Squonk Aug 05 '12 at 03:49
-
Humm. I could have sworn that I had those guys in there, since clearly that is what I had intended. Oh well. Easy fix :) – Frank Sposaro Aug 05 '12 at 06:38
It depends on if you're trying to extend the Activity or Application class. Activity class will go straight through the complete life-cycle like @Frank said. However if you utitilize the Application class:
The onCreate in the application class is only called when the entire application is created, so the Activity restarts on orientation or keyboard visibility changes won't trigger it.
I decided to make this an answer as my initial comment seemed to be misleading.
Reference: Activity restart on rotation Android