星空网 > 软件开发 > 操作系统

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 轻量级存储!

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

上海泰州专线:https://www.goluckyvip.com/tag/88531.html
至泰国物流专线:https://www.goluckyvip.com/tag/88532.html
发泰国陆运专线:https://www.goluckyvip.com/tag/88533.html
发泰国物流专线:https://www.goluckyvip.com/tag/88534.html
去泰国的物流:https://www.goluckyvip.com/tag/88535.html
走泰国的物流:https://www.goluckyvip.com/tag/88536.html
九月初新疆旅游服装搭配(新疆游玩必备衣服清单):https://www.vstour.cn/a/408257.html
黄果树瀑布景区景点 - 黄果树瀑布景区景点分布图:https://www.vstour.cn/a/408258.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流