Here, some useful links are given to start programming in Android Applications-.
Explanation
Run the Application by clicking F11 on either Android Emulator or device. When the views are in portrait mode, it looks like the image, given below,
The state sequence is in the following order when the views are in the portrait state initially,
As soon as the state is changed from portrait to landscape, it looks like the image, given below,
The state sequence is in the following order,
From the above output, we see that the activity is destroyed or resumed when the device changes the orientation from landscape to portrait or vice versa.
Afterward, it again recreates.
Thus, it is very important to understand the behavior because you need to ensure that you take the necessary steps to preserve the state of your activity before it changes orientation. Suppose, your activity may have the variables that contain the values, required for some calculations in the activity. For any activity, you will have to save whatever state you need to save in the onResume() method, which is fired every time the activity changes an orientation.
There is another important behavior to understand. Is it only View which has some Id defined in an activity? They will have their state persisted when the activity they are contained in is destroyed or resumed. Suppose, the user may change an orientation while entering some text into an EditText View. When this happens, any text inside the EditText View will persist; and restored automatically when the activity is recreated.
Conclusion
In the article, you learned the activity behavior when the screen orientation changes. In the next article, I will explain about persisting the state information, when changes in configuration occur.