Android SharedPreferences lightweight storage !, Android lightweight storage

Source: Internet
Author: User

Android SharedPreferences lightweight storage !, Android lightweight storage

First, store the data in the current process, that is, the current project.

SharedPreferences. Editor editor = mContext. getSharedPreferences ("tvplay", Context. MODE_PRIVATE). edit ();
Editor. putString ("video", content. getString ("video "));
Editor. commit ();

This is saved

SharedPreferences preferences = getTargetContext (). getSharedPreferences ("tvplay", Context. MODE_PRIVATE );
Video = preferences. getString ("video ","");

This is

Cross-process SharedPreferences process storage

SharedPreferences. Editor editor = mContext. getSharedPreferences ("tvplay", Context. MODE_WORLD_READABLE). edit ();
Editor. putString ("video", content. getString ("video "));
Editor. commit ();

This is the only difference between storage and above, that is, the mode has changed. You can't understand Baidu!

Private static final String TARGET_PACKAGE_NAME = "com. sdmc. hotel. ollauncher"; // package name of the target data program,

SharedPreferences preferences = getTargetContext (). getSharedPreferences ("tvplay", Context. MODE_PRIVATE );
Video = preferences. getString ("video ","");

Private Context getTargetContext (){
Try {
Return createPackageContext (TARGET_PACKAGE_NAME, Context. CONTEXT_IGNORE_SECURITY );
} Catch (NameNotFoundException e ){
E. printStackTrace ();
}
Return null;
}

This is a result. The difference is that you want to create a context for the process you want to fetch, and then call the getSharedPreferences () method.

Related Article

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.