Android Sharedpreferences Lightweight Storage!

Source: Internet
Author: User

First, the current process is also the current project inside the storage

Sharedpreferences.editor Editor = mcontext.getsharedpreferences ("Tvplay", Context.mode_private). Edit ();
Editor.putstring ("Video", Content.getstring ("video"));
Editor.commit ();

This is the storage

Sharedpreferences preferences = Gettargetcontext (). Getsharedpreferences ("Tvplay", context.mode_private);
Video = preferences.getstring ("video", "");

This is taken

Sharedpreferences process Storage across processes

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 the deposit and the above is the mode change, do not understand Baidu can!

private static final String Target_package_name = "Com.sdmc.hotel.ollauncher";//The 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 different from the above is to create a context for the process you want to take, and then call the Getsharedpreferences () method

Android Sharedpreferences Lightweight Storage!

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.