In my main activity, i have a framelayout which is used to display fragments now imagine, i have 3 fragment objects :
Fragment1 f1 = new Fragment1();
Fragment2 f2 = new Fragment2();
Fragment3 f3 = new Fragment3();
and i set this fragment using :
fragTrans.replace(android.R.id.content, f1);
fragTrans.addToBackStack(null);
fragTrans.commit();
now at different point of times, the app might have one of the three fragments in the framelayout (number of fragments might vary).
So, at some point if i want to identify which of the fragments if being currently displayed in the framelayout, how can i do that ?
My purpose : the fragment2 has say 2 states, where boolean state can be either true or false, if the state is true, and the back button is pressed i want to do something and set state to false and the if the back is pressed i'll call super.onBackPressed() but if it is set to true and if currently fragment 3 is visible, first i want to go to fragment 2, then change the state to false and then super.onBackPressed()
so that will make it piece of cake if i can identify which fragment is currently visible