1

hello I am having an activity which have like 10 fragments I want to check when there is no fragment visible i.e after pressing back button I return to the main activity I want catch this back not back between fragments where no fragment visible I found a way here How to know if a Fragment is Visible? to check by tag name like here but I can't check for all 10 fragments by tag name any help?

Community
  • 1
  • 1
Radwa
  • 325
  • 4
  • 21

1 Answers1

5

If I understood your question right, by using

if (getSupportFragmentManager().findFragmentById(R.id.some_layout_id) != null)

you can find out if the layout with that id contains a fragment or not. This way you don't need to check for each fragment and you can check the fragment container directly. I hope it helps!

Matan Koby
  • 232
  • 1
  • 11