Android:如何更新 PreferenceActivity 中在另一个活动中修改的设置?
我有一个 PreferenceActivity,但某些设置也可以从另一个 Activity 进行修改。但是,当用户从另一个活动修改设置,然后转到 PreferenceActivity 时,此更改不会反映在那里。
如何使外部所做的更改反映在 PreferenceActivity 中?
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.settings);
}
}
这是另一个活动的代码
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(Application.getApplication());
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("my_setting", true);
editor.commit();
I have a PreferenceActivity, but some of the settings can be modified from another Activities also. But when a user modifies a setting from another activity, and then goes to the PreferenceActivity this change is not reflected there.
How can I make the change made from outside be reflected in the PreferenceActivity?
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.settings);
}
}
and here is the code from another activity
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(Application.getApplication());
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("my_setting", true);
editor.commit();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论