How to keep only first added Fragment in back stack (fragment overlapping)?

前端 未结 5 1977
盖世英雄少女心
盖世英雄少女心 2020-12-03 18:06

Scenario what i\'m trying to achieve:

  1. Loading activity with two frame containers (for list of items and for details).
  2. At the app launch time add listF
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 19:03

    You can do this:

    if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
       getSupportFragmentManager().popBackStack(getSupportFragmentManager().getBackStackEntryAt(0).getId(), getSupportFragmentManager().POP_BACK_STACK_INCLUSIVE);
    } else {
       super.onBackPressed();}
    

    In your activity, so you to keep first fragment.

    You shouldn't have, in your first fragment, the addToBackStack. But, in the rest, yes.

提交回复
热议问题