// Context.CONTEXT_IGNORE_SECURITY 忽略安全检测
//getContext().createPackageContext 创建其它应该程序的上下文对象
Context otherContext= getContext().createPackageContext("cn.itcast.preferences", Context.CONTEXT_IGNORE_SECURITY);
SharedPreferences prefence= otherContext.getSharedPreferences("itcast", Context.MODE_PRIVATE);
String nameString= prefence.getString("name", "侯志敏");
int ageInt= prefence.getInt("age", 25);
Log.i(TAG, "name:"+nameString+"========age:"+ageInt);
Android 创建其它应该程序的上下文对象
最新推荐文章于 2025-09-05 16:34:31 发布
