//该activity生成一个SharedPreferences
//1:APK->activity
//包名:com.test.pkg
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
SharedPreferences mPrefs = getSharedPreferences("com.test.pkg_preferences",Context.MODE_WORLD_READABLE );
//注意这里的 Context.MODE_WORLD_READABLE
}
//访问上一个activity的SharedPreferences
//2:APK->activity
public void onCreate(Bundle savedInstanceState)
{
Context otherAppsContext = null;
try
{
otherAppsContext = createPackageContext(
"com.test.pkg", 0);
}
catch (NameNotFoundException e)
{
}
SharedPreferences mPrefs = otherAppsContext.getSharedPreferences("com.test.pkg_preferences",Context.MODE_PRIVATE);
}
阅读(724) | 评论(0) | 转发(0) |