Android Screen switching life cycle

Source: Internet
Author: User

Transfer from Xiaoqlu http://www.cnblogs.com/xiaoQLu/p/3324503.html

Open source helped Android get a rapid development, and open source caused countless fragmentation problems. Android's pre-production system is a semi-finished, immature system and Google's rapid iterative development, resulting in the manufacturers can not keep up with the pace of Google, You 2.3 of the bug has not changed, 4.0 came out, 4.0 of the bug is still processing, 4.1 out, the final result is that the handset manufacturers to each phone a system version, and can not be upgraded. The last bitterness is the vast program apes, you have to consider all versions from 2.1 to 4.3, unless you want to give up those who use the lower version of the phone.

The above is just The spit groove, the following officially started

Some time ago encountered a problem, is the anti-compilation of a program, according to the method of their own to do the same, the key code has been exactly the same, but there is a problem, up to his effect, is the screen switch, activity does not re-create, I spent a long time to think, This is where the problem is, and finally you know, I found that the android:targetsdkversion this property actually affects the life cycle of the screen switching.

As we all know, if you want to solve the screen switching, activity does not re-create, you need to configure the android:configchanges= "Orientation|keyboardhidden" property in manifest, of course, api> 13, you need to add an additional parameter, that is, screensize, do not add this, in the API 13 above the mobile phone will not be effective.

I just want to know why other people's applications only set two properties, android:configchanges= "Orientation|keyboardhidden" can be used in the higher version of the phone, without the need to add additional screensize This attribute, I spent 2 days to think about this problem, just when I was ready to give up, I suddenly saw his targetsdkversion and I was not the same (I saw once, didn't care), holding the mentality of trying, I started my own test again, the miracle happened, It's you. If you set the Targetsdkversion to 12 and below, he will be in the higher version of the phone can also reach the screen switch does not create activity effect, perhaps I see the API is not careful, in fact, this in the English API has been explained, but the online information is too little.

Finally again to summarize the life cycle of the activity at the bottom of the screen, the online related summary There are many, Google, are the same, in fact, I tell you, their summary is only part of the positive solution, the other in the current simulator is not right, I do not know they use the test API is how much, Can't say they are wrong, in their time, I believe he is right, because Google, you know, everything is possible

Let me start by releasing my conclusions.

(1) Set android:configchanges= "orientation" and do not set this property, the two effects are the same, the activity is re-innovation

(2) Horizontal screen cutting vertical screen, as well as vertical screen cut back to the horizontal screen, the two are the same (summarized below), will not appear on the net said horizontal screen cut back to the vertical screen, the life cycle of the implementation of two times the problem

1) Re-create activity life cycle

A) 2.3 on:onsaveinstancestate->onpause->onstop->oncreate->onstart->onrestoreinstancestate-> Onresume

b) 4.0 on (3.2 I didn't test, only tested 4.0):onpause->onsaveinstancestate->onstop->oncreate->onstart-> Onrestoreinstancestate->onresume

2) do not re-create activity, only call onconfigurationchanged

(3) Targetsdkversion will affect the life cycle, targetsdkversion in 12 and below, set the android:configchanges= "Orientation|keyboardhidden", The activity is not recreated on the machine, only the onconfigurationchanged is called, and if the targetsdkversion>12 is set, it only works on the sdkversion<=12 machine,> 12 of the machine activity will be re-created (need to add screensize to effect)

(4) android2.3 and android4.0 life cycle is not the same, 2.3 is first onsaveinstancestate, after onpause,4.0 is first OnPause, after Onsaveinstancestate ( I mean, I don't want to throw up the groove.

All test results are now released (note: The following results do not recreate the activity and re-create the contents of the conclusion 2)

(1) Set android:configchanges= "orientation" and do not set this property, life cycle performance is to recreate activity

(2) Set android:configchanges= "Orientation|keyboardhidden", shown on 2.3 is not re-created activity,4.0 as follows

A) android:targetsdkversion<= "12", life cycle performance is not re-created activity

b) android:targetsdkversion> "12", expressed as re-creation of activity

(3) Set android:configchanges= "Orientation|keyboardhidden|screensize", on 2.3 and 4.0 are not re-created

Android Screen switching life cycle

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.