android4.0 screen Switching (avoid moving the lifecycle of activity)

Source: Internet
Author: User
2012-09-13 16:33 1221 People read comments (2) Collection report recently in the study based on android4.0 new additions to new features actionbar and fragment development, in android4.0 system Actionbar is in the boot ACTI Vity (Actionbar built in) will be shown, typically on the top of the activity reserve space, the leftmost display of the application's icon and title. We know android2.3. Previously, a blank space was reserved above the main activity of the application to display the application title. and the 4.0 system turns this space into the Action Bar space (Actionbar). With regard to the development of Actionbar and fragment, there is no longer a burden here, and later on, I will organize one or two articles on these two knowledge points.

The main point is: when the screen is switched, and then by setting some properties to avoid the activity of the life cycle, that is, when the screen switch, the original activity will be in the screen while the activity of the previous activity destroyed, and then go through the life cycle to establish activity, In this case, when I develop an application with the tab navigation option bar through Actionbar (the content of each tab option corresponds to the resource that the layout of a fragment object obtains, the fragment lifecycle changes as it hosts the activity lifecycle). When the application starts, the default is to open the contents of the first tab option (that is, Tab1 is clicked), then click to show TaB2, show the layout content, this time TAB1 lost click Operation, Natural, its related resources also disappeared. When I rotate the phone screen, the problem arises, and the layout of the Tab1 and TaB2 (TaB2 appears to be the normal expected state) appears at the same time. And our request is only to appear tab2.

Having said so much nonsense, how did the above problem arise? In fact, the solution is simple (that is, to prevent the activity from androidmanifest.xml its lifecycle when the screen rotates) and to add android:configchanges= to the <activity/> in the file. Orientation|keyboardhidden Property (Previous version android2.3), and then overwrite the onconfigurationchanged () method in the class. Well, I cheerfully to try, ni ah, engaged in a long time, played a morning log to find the problem. It's still not settled.

Finally the egg aches to know, the original android4.0 system, has been changed, because when you switch the screen, the screen size also changes (this can be seen from the Actionbar menu bar in the horizontal screen and vertical screen display), so the way it is set up will also change, should be in < Add android:configchanges= "Orientation|screensize" to Activity/> (android3.0 later version). The Onconfigurationchanged () method is then overridden in the activity class.

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.