androidx.fragment.app.FragmentManager.popBackStack()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中androidx.fragment.app.FragmentManager.popBackStack()方法的一些代码示例,展示了FragmentManager.popBackStack()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FragmentManager.popBackStack()方法的具体详情如下:
包路径:androidx.fragment.app.FragmentManager
类名称:FragmentManager
方法名:popBackStack

FragmentManager.popBackStack介绍

暂无

代码示例

代码示例来源:origin: ankidroid/Anki-Android

public void dismissAllDialogFragments() {
  getSupportFragmentManager().popBackStack("dialog", FragmentManager.POP_BACK_STACK_INCLUSIVE);
}

代码示例来源:origin: westnordost/StreetComplete

@Override public void onBackPressed() {
  if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
    getSupportFragmentManager().popBackStack();
  } else {
    super.onBackPressed();
  }
}

代码示例来源:origin: westnordost/StreetComplete

@Override public void onComposeNote(long questId, QuestGroup group, String questTitle)
{
  LeaveNoteInsteadFragment f = new LeaveNoteInsteadFragment();
  Bundle args = QuestAnswerComponent.Companion.createArguments(questId, group);
  args.putString(LeaveNoteInsteadFragment.ARG_QUEST_TITLE, questTitle);
  f.setArguments(args);
  getSupportFragmentManager().popBackStack(BOTTOM_SHEET, FragmentManager.POP_BACK_STACK_INCLUSIVE);
  FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
  ft.setCustomAnimations(
    0, R.animator.quest_answer_form_disappear,
    0, R.animator.quest_answer_form_disappear);
  ft.add(R.id.map_bottom_sheet_container, f, BOTTOM_SHEET);
  ft.addToBackStack(BOTTOM_SHEET);
  ft.commit();
}

代码示例来源:origin: fennifith/Alarmio

@Override
  public void onClick(View view) {
    getFragmentManager().popBackStack();
  }
});

代码示例来源:origin: fennifith/Alarmio

@Override
  public void onClick(View view) {
    getFragmentManager().popBackStack();
  }
});

代码示例来源:origin: saki4510t/libcommon

protected void popBackStack() {
  final Activity activity = getActivity();
  if ((activity == null) || activity.isFinishing()) return;
  try {
    getFragmentManager().popBackStack();
  } catch (final Exception e) {
    Log.w(TAG, e);
  }
}

代码示例来源:origin: KDE/kdeconnect-android

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  if (item.getItemId() == android.R.id.home) {
    FragmentManager fm = getSupportFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
      fm.popBackStack();
      return true;
    }
  }
  return super.onOptionsItemSelected(item);
}

代码示例来源:origin: fennifith/Alarmio

@Override
  public void onClick(View view) {
    getAlarmio().removeTimer(timer);
    getFragmentManager().popBackStack();
  }
});

代码示例来源:origin: pranavpandey/dynamic-support

/**
 * Switch the content fragment use by this activity by using the supplied fragment transaction.
 *
 * @param fragmentTransaction The customised fragment transaction to support animations
 *                            and more.
 * @param fragment The fragment to be used by this activity.
 * @param addToBackStack {@code true} to put previous fragment to back stack.
 * @param tag The fragment tag to maintain the back stack.
 */
protected void switchFragment(@NonNull FragmentTransaction fragmentTransaction,
    @NonNull Fragment fragment, boolean addToBackStack, @Nullable String tag) {
  tag = tag != null ? tag : fragment.getClass().getSimpleName();
  if (getSupportFragmentManager().findFragmentByTag(tag) != null) {
    fragment = getSupportFragmentManager().findFragmentByTag(tag);
  }
  fragmentTransaction.replace(getFragmentContainerId(), fragment, tag);
  if (addToBackStack && mContentFragment != null) {
    fragmentTransaction.addToBackStack(tag);
  } else {
    getSupportFragmentManager().popBackStack(
        null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
  }
  commitFragmentTransaction(fragmentTransaction);
  setContentFragment(fragment, tag);
}

代码示例来源:origin: fennifith/Alarmio

@Override
  public void run() {
    if (isRunning) {
      if (timer.isSet()) {
        long remainingMillis = timer.getRemainingMillis();
        time.setText(FormatUtils.formatMillis(remainingMillis));
        time.setProgress(timer.getDuration() - remainingMillis);
        handler.postDelayed(this, 10);
      } else {
        try {
          FragmentManager manager = getFragmentManager();
          if (manager != null)
            manager.popBackStack();
        } catch (IllegalStateException e) {
          handler.postDelayed(this, 100);
        }
      }
    }
  }
};

代码示例来源:origin: saki4510t/libcommon

@Override
public void onBackPressed() {
  if (DEBUG) Log.v(TAG, "onBackPressed:");
  // Fragment内の子Fragmentを切り替えた時にbackキーを押すと
  // Fragment自体がpopBackされてしまうのに対するworkaround
  final FragmentManager fm = getSupportFragmentManager();
  final Fragment fragment = fm.findFragmentById(R.id.container);
  if (fragment instanceof BaseFragment) {
    final FragmentManager child_fm = fragment.getChildFragmentManager();
    if (child_fm.getBackStackEntryCount() > 0) {
      // HomeFragmentの子Fragmentがバックスタックに有る時はそれをpopBackする
      child_fm.popBackStack();
      return;
    }
    if (((BaseFragment) fragment).onBackPressed()) {
      return;
    }
  }
  super.onBackPressed();
}

代码示例来源:origin: andstatus/andstatus

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case android.R.id.home:
      if (isRootScreen()) {
        closeAndRestartApp();
      } else if(getSupportFragmentManager().getBackStackEntryCount() > 0) {
        getSupportFragmentManager().popBackStack();
      } else {
        finish();
      }
      return true;
    default:
      return super.onOptionsItemSelected(item);
  }
}

相关文章