奇怪的 Android SharedPreferences??

我一開始的寫法
SharedPreferences sp=this.getSharedPreferences("Info", MODE_PRIVATE);

sp.edit().putString("Id", "GGYY");
sp.edit().commit();


String x= sp.getString("Id","YYGG");
上面的寫法會導致一直無法寫入設定,所以x都是YYGG的預設值
一定要寫成
Editor e = sp.editor();

e.putString("Id", "GGYY");
e.commit();


String x= sp.getString("Id","YYGG");
這樣 x 就會變成之前儲存的 GGYY,怎麼會這樣呢??

留言

這個網誌中的熱門文章

好貴的東元冷氣維修--馬達啟動電容

台大醫院 婁培人 耳鼻喉科 就診

機車無法充電之整流器壞掉--$650