在Android的共享prefrences [英] SharedPrefrences in Android
本文介绍了在Android的共享prefrences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用的共享prefrences保存在主要活动。现在的一些细节我想在其他一些活动的细节,但我不能够得到它们。
I have used SharedPrefrences to save some details in the Main Activity .Now i want to get the details in some other activity but i am not able to get them .
code保存
public void saveInformation(String username,String password) {
SharedPreferences shared = getSharedPreferences("shared", MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
}
code要获得
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
String username = prefs.getString("username", null);
但是,这不是为我工作。请建议我怎么能得到他的
But this is not working for me .Please suggest me how could i get his
推荐答案
code拿到应
SharedPreferences prefs = getSharedPreferences("shared", MODE_PRIVATE);
这篇关于在Android的共享prefrences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文