I'm trying to setup in my app that is using androidX.
My problem is that when I try to work with PlaceAutocompleteFragment I get errors because it is a fragment from android.app.fragment
and my parent fragment is an androidx fragment: androidx.fragment.app.Fragment
so it uses a androidx.fragment.app.FragmentManager
instead of a android.app.FragmentManager
.
How can I work with "old" fragments in androidX?
FragmentManager is class provided by the framework which is used to create transactions for adding, removing or replacing fragments. getSupportFragmentManager is associated with Activity consider it as a FragmentManager for your Activity .
FragmentManager is the class responsible for performing actions on your app's fragments, such as adding, removing, or replacing them, and adding them to the back stack.
This class was deprecated in API level 28. Use the Support Library androidx.
implementation 'androidx.appcompat:appcompat:1.0.2'
.import androidx.fragment.app.FragmentTransaction;
.Activity
to AppCompatActivity
. getFragmentManager()
to getSupportFragmentManager()
. This will fix your issue.
If you are using the new libraries then only use those, don't combine them bacause yo can run into more problems. Now for your problem go to your fragment and just change the import form:
import android.app.fragment
To:
import androidx.fragment.app.Fragment
That should solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With