【问题标题】:Android Up navigation: returning from child to parent activity selecting the correct fragmentAndroid向上导航:从子活动返回到父活动选择正确的片段
【发布时间】:2014-10-21 03:39:49
【问题描述】:

我有一个应用程序,它在导航抽屉中有 3 个部分,部分 X、Y、Z,这些部分分别作为片段实现,现在我有 3 个详细活动 A、B、C,部分与这些详细信息相关活动如下 X -> A, Y -> B, C -> Z,但在某些情况下,活动 A 具有到活动 B 的链接,并且在 A -> B 的流程中,我在活动 B 中的向上导航应该重定向到显示正确部分的父级,在 B 的情况下为 Y,有没有办法做到这一点?我已经为每个细节活动定义了我的父活动(抽屉活动),并且主页按钮似乎正在工作,但是我需要以某种方式向主页按钮意图传递一个额外的东西(我相信它必须使用一些意图来打开父活动),我该如何完成?

【问题讨论】:

    标签: android android-intent android-fragments navigation


    【解决方案1】:
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
                case android.R.id.home:
                    Intent upIntent = new Intent(this, MainActivity.class);
                    upIntent.putExtra("OpenFragment", "YourFramentNumber");
                    NavUtils.navigateUpTo(this, upIntent);
                    return true;
                default: return super.onOptionsItemSelected(item);
            }
        }
    

    在您的导航活动中获取此意图,并使用函数相应地转换到所需的Fragment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多