在4.4上是有效的,高版本不保证
存储端程序关键代码App1
SharedPreferences pref = getContext().getSharedPreferences("File", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean("para", true);
editor.apply();读取端程序关键代码App2
try {
Context app1Context = context.createPackageContext(App1_PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences sh = app1Context .getSharedPreferences("File", Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS);
sh.getBoolean("para", false);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
本文提供了在Android应用程序之间使用SharedPreferences进行数据共享的具体示例。详细展示了如何在一个应用中存储布尔值,并在另一个应用中读取该值的过程。

4597

被折叠的 条评论
为什么被折叠?



