Android为TV端助力 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()方法
最新文章
- 在微软伪静态处理机制下action导致伪静态的地址重现的问题
- Json.NET读取和写入Json文件
- Android深度探索--HAL与驱动开发----第四章读书笔记
- 使用markdown编辑evernote(印象笔记)的常用方法汇总
- zookeeper初识之原理
- jQuery 事件用法详解
- 对.NET的认识
- android开发之重写Application类
- Core OS 层
- 【转】C++虚函数解析
- hudson任务配置说明
- 使用JS实现鼠标悬浮切换显示
- MySQL replication illegal mix of collations
- 监督学习——logistic进行二分类(python)
- CODING 敏捷实践完全指南
- tensorflow, TypeError:'Tensor' object is not callable
- luogu P1762 偶数
- 我的Visual Studio必用工具
- Java中如何遍历Map对象
- C/C++之宏、内联函数和普通函数的区别
热门文章
- Scala - 快速学习04 - 求值策略
- socket 实现单一串口共享读写操作
- [原创]K8 DB_Owner权限GetShell工具
- 在 .NET Core 下的 Swagger UI 自定义操作
- 关于 Kubernetes 中的 Volume 与 GlusterFS 分布式存储
- Android权限大全(链接地址整理)
- 从零基础到拿到网易Java实习offer,谈谈我的学习经验
- Java单元测试(Junit+Mock+代码覆盖率)
- Python快速学习03:运算 &; 缩进和选择
- 面试必备技能-HiveSQL优化