安卓第一行代码之SharedPreference

1.获取SharedPreference的方式:

context.getSharedPreference

activity.getPreference()

PreferenceManager.getDefaultSharedPreference()

2.数据存储

SharePreference.Editor editor = getSharedPreference("path",MODE_PRIVATE).edit();

 editor.putString("key1","value1");

 editor.putInt("key2",12);

    ······

editor.apply();


3.数据读取

SharePreference.Editor editor = getSharedPreference("path",MODE_PRIVATE).edit();

String receive1 = editor.getString("key1");

······


你可能感兴趣的:(安卓第一行代码)