Android 创建其它应该程序的上下文对象
生活随笔
收集整理的這篇文章主要介紹了
Android 创建其它应该程序的上下文对象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// 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 创建其它应该程序的上下文对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 马桶盖松动怎么办图解?
- 下一篇: 数字一到十怎么读?