我创建了一个 PreferenceFragment。如何保存更改的首选项并通过应用重启加载?我的第二个问题:如何从另一个班级获得偏好值?
我的偏好活动
public class PrefsActivity extends ActionBarActivity {
public static PrefsFragment mPrefsFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager mFragmentManager = getFragmentManager();
FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();
mPrefsFragment = new PrefsFragment();
mFragmentTransaction.replace(android.R.id.content, mPrefsFragment);
mFragmentTransaction.commit();
}
}
还有我的 PrefsFragment
public class PrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}