Activity lifecycle Call when Android configuration is switched vertically

Source: Internet
Author: User

Question: What is the life cycle of the activity when switching between screens?

Test environment: Huawei Mate7

Package Com.virglass.beyond.activity;import Android.app.activity;import Android.content.res.configuration;import Android.os.bundle;import com.virglass.beyond.utils.logutil;/** * System Settings Change * @author Administrator * */public class  Configurationactivity extends activity{@Override protected void onCreate (Bundle savedinstancestate) {//        TODO auto-generated Method Stub super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_configuration);    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = OnCreate");        } @Override protected void OnStart () {//TODO auto-generated Method Stub Super.onstart ();    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = OnStart");        } @Override protected void Onrestart () {//TODO auto-generated Method Stub Super.onrestart ();    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = Onrestart");     } @Override protected void Onresume () {//TODO auto-generated Method Stub super.onresume ();   LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = Onresume");        } @Override protected void OnPause () {//TODO auto-generated Method Stub super.onpause ();    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = OnPause");        } @Override protected void OnStop () {//TODO auto-generated Method Stub super.onstop ();    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = OnStop");        } @Override protected void OnDestroy () {//TODO auto-generated Method Stub Super.ondestroy ();    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = OnDestroy"); } @Override public void onconfigurationchanged (Configuration newconfig) {//TODO auto-generated method s        Tub super.onconfigurationchanged (newconfig);    LOGUTIL.E ("Jintuo", "= = = = = = = = = = = = Onconfigurationchanged"); }}

1, the first case: Androidmainfist does not set the activity android:configchanges

<activity       android:name= "Com.virglass.beyond.activity.ConfigurationActivity" ></activity>

Vertical screen switch to horizontal screen Log print as follows:


Horizontal screen switch to vertical screen log print as follows:


Summary: Androidmainfist do not set the activity of the android:configchanges when the horizontal screen switch vertical screen/vertical screen switch horizontal screen activity each life cycle method is called only once.


2. The second case: when setting the activity's android:configchanges= "orientation"

<activity      android:name= "com.virglass.beyond.activity.ConfigurationActivity"      android:configchanges= " Orientation "></activity>


Vertical screen switch to horizontal screen Log print as follows:


Horizontal screen switch to vertical screen log print as follows:


Summary: The vertical screen switch horizontal screen first call Onconfigurationchanged () method, and then call activity each life cycle method, horizontal screen switch to vertical screen only off with onconfigurationchanged () method.

3. The third case: when setting the activity's android:configchanges= "Orientation|keyboard|keyboardhidden|screensize"

<activity      android:name= "com.virglass.beyond.activity.ConfigurationActivity"      android:configchanges= " Orientation|keyboard|keyboardhidden|screensize "></activity>


Vertical screen switch to horizontal screen Log print as follows:


Horizontal screen switch to vertical screen log print as follows:



Summary: Horizontal screen switch to vertical screen, vertical screen switch to horizontal screen each call Onconfigurationchanged () method


4. Fourth situation: When you set the activity's android:configchanges= "Orientation|keyboard|keyboardhidden", one or more of the execution results are the same as the second result.

5, the fifth situation: in the third case based on the activity of the android:screenorientation= "portrait" attribute, the screen switch without any printing.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Activity lifecycle Call when Android configuration is switched vertically

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.