Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

androidx getFragmentManager() has been deprecated

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

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

What to do?

like image 679
Martin Zeitler Avatar asked Feb 04 '20 04:02

Martin Zeitler


People also ask

What can I use instead of Getfragmentmanager?

Yes, using the support library Fragment along with the getSupportFragmentManager is the right thing to do.

What is Getfragmentmanager?

we will use getChildFragmentManager() Return a private FragmentManager for placing and managing Fragments inside of this Fragment. we will use getParentFragmentManager() Return the FragmentManager for interacting with fragments associated with this fragment's activity.

How do I get child fragment manager?

Short answer: I call and use getChildFragmentManager() in my Fragment's onViewCreated() method. For example: @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.


2 Answers

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.

like image 195
Martin Zeitler Avatar answered Sep 27 '22 18:09

Martin Zeitler


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

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

like image 40
Md. Arif Avatar answered Sep 27 '22 18:09

Md. Arif