New read about lost data on Android spin screen

Source: Internet
Author: User

Based on previous experience, it was thought that when the Android screen was rotated, oncreate () would be recalled, causing all the data on the interface to be reset, and the activity to be set to a property in manifest in order for him not to go back to the OnCreate method. or cumbersome, you need to onSaveInstanceState() Save all of the interface data in the method, and then restore the data in the Onrestoreinstancestate () method.

Until today to see this sentence:

“by default, the system uses theBundleinstance State to save information on eachViewobject in your activity layout (such as the text value entered to anEditTextobject). So, if your activity instance are destroyed and recreated, the state of the layout is restored to its previous state with N o Code required by you. However, your activity might has more state information so you ' d like to restore, such as member variables so track T He user ' s progress in the activity.”

By default, bundles are used to hold the instance state of each view object in the layout (for example, text written into EditText). So when your activity is destroyed and rebuilt, you don't have to write any code to restore the layout state. However, your activity may have some other information you need to store, such as the value of the member variable that holds the user's current progress.


I feel very strange to see this, and my experience does not match, and a new one only EditText demo rotation screen test, edittext in the text will be lost because of rotating the screen. Think of the solution and see the sentence:

    "note:  in order for the Android system to restore the state of the views in your Activit y,  each View must has a unique ID android:id  attribute. "

Android system storage and restore view status must have a unique ID


After setting the ID for EditText, the data is automatically restored after the screen is rotated.

New read about lost data on Android spin screen

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.