首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

SharedPreferences保存数据和在别的应用程序里面怎么访问

2012-09-17 
SharedPreferences保存数据和在别的应用程序里面如何访问package cn.itcast.otherimport android.content

SharedPreferences保存数据和在别的应用程序里面如何访问

package cn.itcast.other;import android.content.Context;import android.content.SharedPreferences;import android.test.AndroidTestCase;import android.util.Log;public class AccessOtherAppPreferenceTest extends AndroidTestCase {private static final String TAG = "AccessOtherAppPreferenceTest";public void testAccessOtherAppPreference() throws Throwable{//String path = "/data/data/cn.itcast.preferences/shared_prefs/itcast.xml";//File file = new File(path);// SAX来完成xml文件的解析,才能得到参数Context otherContext = getContext().createPackageContext("cn.itcast.preferences",Context.CONTEXT_IGNORE_SECURITY);SharedPreferences preferences = otherContext.getSharedPreferences("itcast", Context.MODE_PRIVATE);String name = preferences.getString("name", "");int age = preferences.getInt("age", 20);Log.i(TAG, "name="+ name + ",age="+ age);}}

?

热点排行