findFragmentByScreen 🧐
Hi There !!
Chances are that in any point of your career, you would had to work on an existing codebase. Things are fine if the code is well documented, it is built by following certain design pattern or guidelines. The code is modularised depending upon the feature type. Things gets difficult when none of that is taken care of.
Recently, I was going through the same episode. The repo was huge with one single activity responsible for hosting multiple fragments. First thing first was to understand what fragment is associated for which screen. I had been using the old way till now :
Layout inspector -> Identify widget id -> find usage -> go to the layout xml -> find usage to find which fragment is using this layout -> 🙂
As you can imagine, this was a tedious and slow way to do it😐
I came across the following callback that allows us to listen to fragment lifecycle events happening in Activity’s FragmentManager. It has other lifecycle callbacks that you can use based upon your needs
Or alternatively you can use fragmentManager.addFragmentOnAttachListener