我在ViewPager中有ListFragments,每个ListFragment
都包含在一个活动中,并且有自己的选项菜单项,用户可以单击/点击以启动名为addEditItem
的活动。现在,我想在addEditItem
活动中provide up navigation,按该活动中的主页按钮(向上按钮)将返回ListFragment
。我不知道我们是否可以Fragment
指定Activity
作为optionsItemSelectedItem
的父级specify activies.我在addEditItem
内部NullPointerException at navigateUpTo
活动中尝试的内容如下(但这是通过@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new
// task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
Log.i(MyConstants.LOG_TAG, "navigate up to");
try {
NavUtils.navigateUpTo(this, upIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
):
{{1}}