我有一个打开 PreferenceScreen 的活动。当我单击“返回”时 - 我希望首选项屏幕将关闭,我将返回活动,但相反 - 当前活动已关闭,我将返回上一个活动。我该如何解决?
public class MyActivity extends Activity {
//....
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return (new Helper()).onOptionsItemSelected_menu(item,this,mFragmentManager);
}
}
public class Helper {
// ....
public boolean onOptionsItemSelected_menu(MenuItem item, Activity activity, FragmentManager mFragmentManager)
{
switch (item.getItemId()) {
case R.id.action_settings:
MenuHelper.settings(activity, mFragmentManager);
return true;
default:
return onOptionsItemSelected_menu(item, activity, mFragmentManager);
}
}
public static void settings(Activity activity, FragmentManager mFragmentManager) {
FragmentTransaction mFragmentTransaction = mFragmentManager
.beginTransaction();
PrefsFragment mPrefsFragment = new PrefsFragment(activity);
mFragmentTransaction.replace(android.R.id.content, mPrefsFragment);
mFragmentTransaction.commit();
}
public static class PrefsFragment extends PreferenceFragment {
Activity m_activity;
public PrefsFragment(Activity activity)
{
m_activity = activity;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}