http://xiechengfa.iteye.com/blog/1077355

//该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);
}
//备注:不同的APK互相访问对方的资源文件或图片也可以使用此方法(otherAppsContext )。

相关文章:

  • 2022-12-23
  • 2021-07-31
  • 2021-09-08
  • 2022-12-23
  • 2021-12-19
  • 2021-06-13
猜你喜欢
  • 2022-12-23
  • 2021-03-30
相关资源
相似解决方案