FragmentManager
is deprecated. Is there an alternative or what can I do now?
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocomplet
I used parentFragmentManager
instead of fragmentManager
.
(If you are using androidx Fragment
.)
https://developer.android.com/jetpack/androidx/releases/fragment#1.2.0
getFragmentManager() deprecation: The
getFragmentManager()
andrequireFragmentManager()
methods onFragment
have been deprecated and replaced with a singlegetParentFragmentManager()
method, which returns the non-nullFragmentManager
theFragment
is added to (you can useisAdded()
to determine if it is safe to call).
Xml
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.SupportPlaceAutocompleteFragment"
/>
Activity
SupportPlaceAutocompleteFragment autocompleteFragment = (SupportPlaceAutocompleteFragment)
getSupportFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
This method was deprecated in API level 28.
Use FragmentActivity.getSupportFragmentManager()
If you using AndroidX Fragment androidx.fragment.app.Fragment
you can use
getActivity().getSupportFragmentManager()
Use This
import android.support.v4.app.FragmentManager;
Instead of
import android.app.FragmentManager;
And Use This
FragmentManager manager = ((YourActivity) mContext).getSupportFragmentManager();
Instead of
FragmentManager manager = ((YourActivity) mContext).getFragmentManager();
You should use the Fragment class from Android Support library instead.
android.app.Fragment was deprecated in API level 28. Use the Support Library Fragment for consistent behavior across all devices and access to Lifecycle.
Use android.support.v4.app.Fragment instead.