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.