设为首页 加入收藏

TOP

android SharedPreferences 轻量级存储!
2017-10-13 09:57:18 】 浏览:1183
Tags:android SharedPreferences 轻量级 存储

首先在当前进程也就是当前的项目里面进行存储

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

这是存

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

这是取

跨进程SharedPreferences进程存储

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

这是存跟上面存唯一不同就是模式换了,不懂可以百度!

private static final String TARGET_PACKAGE_NAME = "com.sdmc.hotel.ollauncher";// 目标数据程序的包名,

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;
}

这是取,跟上面不同的就是要创建一个你要取的进程的context,然后在调用getSharedPreferences()方法

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇大神博客 下一篇android SharedPreferences 轻量..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目