我知道以前有人问过它,但它似乎对我不起作用。
我preferences.xml
在文件夹中有一个 XML 文件res\xml
。它包含一个像这样的选项屏幕:
<PreferenceScreen>
<EditTextPreference
android:name="prfEmail"
android:summary="Your account's e-mail address"
android:title="E-mail"
android:key="prfEmail" />
</PreferenceScreen>
我可以从中进行活动,并且显示良好。现在我想从这些偏好中读取值,但我似乎找不到它。在另一项活动中,我做:
SharedPreferences appSharedPrefs;
appSharedPrefs = getSharedPreferences("preferences",Activity.MODE_PRIVATE);
String restoredText = appSharedPrefs.getString("prfEmail",null);
当我想打印它null
返回的这个值时。我究竟做错了什么?