During work, the project needs to rotate the screen often, as well as the tablet. So you will often consider the Android screen rotation life cycle, so there are corresponding processing methods. There are two main ways to solve this problem. is specific to the life cycle of the screen rotation. When the screen rotates, the activity is destroyed to the rebuild process without any processing. This effect is not desired.
One, method one
Is the activity in the config file plus this
Android:configchanges= "Keyboardhidden|orientation|screensize" This sentence means to configure double quotes inside the parameter meaning, soft keyboard hidden, direction, screen size
Android 3.0 to add screensize after.
<activity android:name= "cn.com.karl.my.MySetNewsActivity" android:configchanges= "keyboardhidden| Orientation|screensize "> > </activity>
then the activity overrides the following method. What needs to be done at the time of rotation is also written in this method.
Override rotation method, do not destroy Activity@overridepublic void onconfigurationchanged (Configuration newconfig) { Super.onconfigurationchanged (newconfig);}
look at the rotation of the life cycle, this picture is from a blog image, in the end I will indicate the source.
Second, method two
Do not write the configuration of the activity in the configuration file. All let it be destroyed in the reconstruction, but in this process, the necessary, important values are saved up. After rebuilding, it's OK to take it out. I am not quite in favor of this use, resources are not fully used. Take a look at the two ways you need to rewrite.
@Overrideprotected void Onsaveinstancestate (Bundle outbundle) {super.onsaveinstancestate (outbundle); Outbundle.putboolean ("Roadchange", Mchange);} @Override protected void Onrestoreinstancestate (Bundle savedinstancestate) {super.onrestoreinstancestate ( savedinstancestate); mchange = Savedinstancestate.getboolean ("Roadchange");}
life cycle such as:
This blog refers to the life cycle of the activity when the Android screen rotates. The above two pictures are also from this blog.
Reprint please indicate the source of the blog site: http://blog.csdn.net/qq_16064871
If there is a reprint does not indicate the source of the blog URL, or did not get the author's consent. The author holds copyright ownership.
Android screen rotation life cycle and how to handle it