2011-01-25 4 views
0

ted을 저장할 단축 프로그램을 으로 작성한 다음 에 값을로드하려고합니다. getString을 사용하여 값을로드하면 boardstr 값이 변경되지 않습니다.환경 설정을 사용하여 데이터를 저장하려고하는 Android

boardstr= new String();  
boardstr="fred"; 
// set the prefrence to ted 
this.getPreferences(MODE_PRIVATE).edit().putString("board","ted"); 
// kload the prfrence in boardstr 
this.getPreferences(MODE_PRIVATE).getString("board",boardstr); 
// boardstr stil equals fred, not ted 

답변

4

는 당신도 그들에게 위해 commit() 또는 apply() 변경 사항을 저장하고 적용 할 필요가있다.

예컨대 :

// set the prefrence to ted 
this.getPreferences(MODE_PRIVATE).edit().putString("board","ted"); 
this.getPreferences(MODE_PRIVATE).edit().apply(); 
+0

가 속임수를 썼는지 그, 감사합니다! –