我目前正在开发一个由管理多个片段的基本活动组成的应用程序。其中一个片段是一个列表,当单击一个项目时会启动一个详细信息活动。我希望当我单击主页按钮(使用 ABS)让应用程序导航回 listfragment 时,但它总是导航回我指定为默认值的片段。
Base Activity
Frag1 - Default
Frag2
Frag3 -> DetailsActivity
当从DetailsActivity按下主页按钮时,我想回到Frag3而不是我去Frag1。
任何帮助都会很棒。这是我在细节活动中处理按下主页按钮的代码。
主要活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set the Above View
if (savedInstanceState != null)
mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
if (mContent == null)
mContent = new HomeFragment();
// set the Above View
setContentView(R.layout.content_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, mContent)
.commit();
// set the Behind View
setBehindContentView(R.layout.menu_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new SlidingMenuFragment())
.commit();
// customize the SlidingMenu
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}
@Override
public void onSaveInstanceState(Bundle outState) {
getSupportFragmentManager().putFragment(outState, "mContent", mContent);
super.onSaveInstanceState(outState);
}
public void switchContent(Fragment fragment) {
getSlidingMenu().showContent();
mContent = fragment;
getSupportFragmentManager()
.beginTransaction()
.addToBackStack("test")
.replace(R.id.content_frame, fragment)
.commit();
}
子活动:
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}