2012-02-29 62 views
2

我正在将iOS应用程序迁移到android,并考虑iOS,我设置了一个默认的plist文件,其中使用NSuserDefaults修改了字符串和键。我阅读了一些文章和文档,但并不清楚如何在Android中正确执行此操作。 我需要一个首选项文件,包含我可以读写的键和字符串。谢谢。android读/写用户偏好

回答

19
SharedPreferences settings; 
settings = getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE); 

//get the sharepref 
int id = settings.getInt("ID", 0); 

//set the sharedpref 
Editor editor = settings.edit(); 
editor.putInt("ID", "1"); 
editor.commit(); 
+1

虽然简单的RTFM是合理的,但我必须承认使用您的答案:)谢谢! – 2014-03-03 10:08:41