public abstract Context createPackageContext (String packageName, int flags)
Return a new Context object for the given application name. This Context is the same as what the named application gets when it is launched, containing the same resources and class loader. Each call to this method returns a new instance of a Context object; Context objects are not shared, however they share common state (Resources, ClassLoader, etc) so the Context instance itself is fairly lightweight.
Throws PackageManager.NameNotFoundException if there is no application with the given package name.
Throws SecurityException if the Context requested can not be loaded into the caller's process for security reasons (see CONTEXT_INCLUDE_CODE for more information}.
Parameters
| packageName | Name of the application's package. |
|---|---|
| flags | Option flags, one of CONTEXT_INCLUDE_CODE or CONTEXT_IGNORE_SECURITY. |
Returns
- A Context for the application.
Throws
| java.lang.SecurityException | |
| if there is no application with the given package name | |
| PackageManager.NameNotFoundException |
本文介绍如何在Android应用间通过设置权限为MODE_WORLD_READABLE的SharedPreferences实现数据共享。示例展示了从应用A创建并编辑偏好设置,在应用B中读取这些设置的过程。
881

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



