Save simple application data

Source: Internet
Author: User

For Android applications, there are two lightweight techniques for saving simple data-shared preference and a pair of Event Handlers used to save the details of the activity instance. Both mechanisms use the name/value (NVP) mechanism to store simple basic types of values.

 

With shared preference, you can create a name table for the key/value pair in your application, which can be shared among components running in the same context.

 

Shared preference supports the following data types: Boolean, String, float, long, and integer. It is the best way to quickly store default values, class instance variables, current UI status, and user settings. Most of them are used for data storage between user sessions and sharing settings between program components.

 

In another optional way, activity provides onsaveinstancestate processing functions. It is designed to save the UI status of the activity that becomes the terminated object when resources are running in short supply.

 

The working mechanism of processing functions is similar to the shared preference mechanism. It provides a bundle parameter that represents the basic type of the key/value table and can be used to save the value of the activity instance. This bundle will be passed into the oncreate and onrestoreinstancestate methods in the form of parameters later.

 

The bundle of the UI state is used to record the value of the activity required to render the same UI after unexpected restart.

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.