0.視頻地址:http://www.imooc.com/video/3265 1.使用SharePreferences存取數據: public class MainActivity extends Activity { @Override protected void onCreate(Bundle ...
0.視頻地址:http://www.imooc.com/video/3265
1.使用SharePreferences存取數據:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(MainActivity.this); //方法2:SharedPreferences //pref=getSharedPreferences("mypref",MODE_PRIVATE); Editor editor=pref.edit(); editor.putString("name", "王二"); editor.putBoolean("default", true); editor.putInt("age", 30); editor.putLong("time", System.currentTimeMillis()); editor.commit();//提交 //System.out.println(pref.getInt("age", 0)); } }View Code
2.如何取值?
3.如何查看數據文件? 1)運行程式,然後打開DDMS>File Explorer>data>data>包名>shared_prefs>pref.xml>導出 2)打開文件: