Shapedperference use the problem to be noted

Source: Internet
Author: User

These two days change colleague Intercept assistant bug but changed, find for a long time did not find the wrong reason, finally carefully think of a multi-process to share data problem, finally found the problem, is he in a service to read the configuration file, and modify the configuration file is in an activity inside, He set the service to be in a process that is not the same process as the activity, resulting in inconsistent data and read data after Setup.

The best place to use sharedpreference is to keep the configuration information, and the data store in Android with a preference-specific preferencefragment is also stored using sharepreference, the default file name is (your PackageName) in _preferences.xml. If you want to modify the default file name, you can do so by using Getpreferencemanager () in preferencefragment. Setsharedpreferencesname ("Modify_default_ Preference ") to change the default file name.

None of this matters. It is important to modify the same value in a multi-process problem. To facilitate the description, the process of creating a sharedpreference XML for the first time is described as the primary process, and the second time that the XML file is used is the secondary process

Different processes refer to the different processes seen in DDMS, including different applications (Shareduid also in the same), and the process generated by the configuration process in the same application. The communication between them will cause the main process to modify the value, which is read by the secondary process when it is initialized the first time.


Shapedperference use the problem to be noted

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.