androidx getFragmentManager() has been deprecated
Asked Answered
R

3

19

Getting deprecation warnings for androidx.fragment.app.Fragment:

warning: [deprecation] getFragmentManager() in Fragment has been deprecated.

What to do?

Ruelu answered 4/2, 2020 at 4:59 Comment(0)
R
18

The sources of version 1.2.0 explain it in more detail:

This has been removed in favor of getParentFragmentManager(), which throws an IllegalStateException if the FragmentManager is null. Check if isAdded() returns false to determine if the FragmentManager is null.

Ruelu answered 4/2, 2020 at 4:59 Comment(3)
It is explicitly mentioned in the Javadoc, no need to look at the source.Sapphire
In short, you should use getParentFragmentManager() instead of getFragmentManager() or requireFragmentManager() since both got deprecated in androidx.fragment.app.FragementSultan
The name is confusing. I want the manager of the current fragment and not of it's parent. Google's changed code looks like the only point is the change itself...Springe
V
6

In Kotlin: fragmentManager, requireFragmentManager() are deprecated.
Current way: parentFragmentManager

In JAVA: getFragmentManager(), requireFragmentManager() are deprecated.
Current way: getParentFragmentManager()

Vaccine answered 11/3, 2022 at 5:50 Comment(0)
H
1

Deprecation of getFragmentManager():

The getFragmentManager() and requireFragmentManager() methods on Fragment have been deprecated and replaced with a single getParentFragmentManager() method, which returns the non-null FragmentManager the Fragment is added to (you can use isAdded() to determine if it is safe to call).

Use Google Docs for more reference

Hardpressed answered 4/2, 2020 at 5:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.