使用Android中的向上导航模式从活动导航到片段

时间:2013-07-17 05:09:21

标签: android android-intent android-fragments

我在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}}

0 个答案:

没有答案