One, what happens when the device spins?
when the device rotates, the current Activity The instance is destroyed by the system and then creates a new Activity instance.
Next we examine the activity's life cycle to see:
The above is the event that occurred sequentially when I started the activity, and then I rotated the device:
As you can see, when you rotate, the first activity is destroy off, and then the new activity is created.
two, understanding of equipment configuration and alternative resources
Rotating the device will change the device configuration. A device configuration is a series of features used to describe the current state of a device. These features include: screen orientation, screen size, screen density (a fixed device configuration that cannot be changed at run time), keyboard type, base mode, and language.
as long as the device configuration changes while the app is running, Android destroys the current activity, and then create a new activity.
third, use the new layout after rotating the device
, create a new Layout-land folder under the Res folder, create a new layout file with the same name, then, when the device goes to the level, the new activity will automatically use the horizontal layout file under this folder.
Four, how to save the current temporary data before the device spins?
Similar to the refresh in the Web, when I refresh, the current page of the temporary data are cleared, such as I am currently filling out a form, the choice of gender female, refresh, and re-fill. Obviously, there is a hidden bug in the device rotation, so how do you deal with this problem of saving temporary data in Android?
We can implement this by overriding the Onsaveinstancestate method.
First, write the data you want to save in this method:
After that, we re-load the data in the OnCreate method:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
android--processing equipment Rotation activity destruction temporary data loss problem