Use sharedpreference and object stream to store objects

Source: Internet
Author: User

The preferencesutils tool class can be a simple object (it can cache all the simple attributes of public in the object)

In addition, the differences between preference storage and direct use of object file caching methods are studied. 1. Efficiency in file writing for the first time. Direct cache of object files is faster than preference. 2. Size, the direct cache object file is smaller than the preference file. 3. The cache directory is different. The preference file is cached in shared_prefs. Based on our settings, you can select the directory where two operations are performed to clear the cache: files under the Data/application/caches directory will be deleted to clear the data: All files except the lib directory will be deleted, including shared_prefs, if the selected directory for caching object files is not under caches and files or other directories are used, the only disadvantage of preference and preference also disappears. In essence, they are all read/write operations, but preference uses XML storage, which means there are redundant nodes and redundant conversions. In the second write, sharedpreferencesimpl uses other mechanisms, so it performs very fast. Next we will discuss the storage principle of sharedpreference to see if its cache mechanism is suitable for objects with frequently changed content. Source code: https://github.com/AltasT/PreferenceVObjectFilehttps://github.com/AltasT/PreferenceVObjectFile/archive/master.zip

Use sharedpreference and object stream to store objects

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.