Android activity life cycle and screen shift problem

Source: Internet
Author: User

You rewrite the activity of several life cycle methods, run to know what is going on, really lazy people can see: Click to open the link.

OnCreate: Executes when the activity is created and executes only once.

OnStart: Executes when the interface is visible.

Onresume: The interface gets the focus, and the button executes when it is clicked.

OnPause: The interface loses focus and the button does not click.

OnStop: Performed when the interface is not visible.

OnDestroy: Destroy, execute only once.


Onrestart: Occurs before the interface, is not destroyed, the invisible state returns to the visible state, executes the Onrestart and executes the OnStart

Usage scenarios:
1. Application exits auto-save data ondestory OnCreate
2. Application minimized paused operation OnStop OnStart video player
3. Pause the game and start the foreground life cycle



The screen has an impact on the activity life cycle!!

Vertical screen switch to horizontal screen will be destroyed in the creation, if you do not do processing, then the data will be lost!

Horizontal screen switch to vertical screen will have two life cycle, the middle will be destroyed, the data will be lost.

Solution: Add the phrase red:


<activity android:name= ". Mainactivity "android:label=" @string/app_name "          android:configchanges="orientation| Keyboardhidden|screensize">

Orientation: Eliminate the influence of the screen.

Keyboardhidden: Eliminating keyboard effects

ScreenSize: Eliminate screen size change effect, this property can not be set before 4.0, 4.0 and above must be set.




Android activity life cycle and screen shift problem

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.