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);

posted @ 2012-05-17 21:22  左正  阅读(359)  评论(0编辑  收藏  举报