getSupportFragmentManager().getFragments() shows a compile time error
As noticeable in the FragmentManager
documentation, getFragments()
is not a public method available to apps, but an internal implementation detail of the Support Library, hence the use of the RestrictTo
annotation that was added to prevent usage of private APIs.
You'll want to change your code to not use getFragments
and only use the public APIs.
Alternative For those who may be using getFragments()
in their coding, I have replaced my code to get last fragment in backstack
to this code(I am using this code in onBackPressed()
to apply changes according to currentFragment
assumed all fragments are added to backstack):
FragmentManager.BackStackEntry backStackEntryAt = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1);currentFragment = backStackEntryAt.getName();
You can use (make sure using 25.2.0 or higher )
supportFragmentManager.registerFragmentLifecycleCallbacks(object : FragmentManager.FragmentLifecycleCallbacks() { override fun onFragmentAttached(fm: FragmentManager?, f: Fragment?, context: Context?) { f?.let { fList.add(it) } } override fun onFragmentDetached(fm: FragmentManager?, f: Fragment?) { f?.let { fList.remove(it) } }}, false)
Instead of using getFragments()