I encountered to a problem related to Activity's getFragmentManager() incossitency with androidx.FragmentManager.
So I have the following method:
public void myMethod(Activity activity) {
/**
* do some staff here
*/
//now we should open a DialogFragment
new MyCustomDialogFragment().show((activity).getFragmentManager(), MyCustomDialogFragment.TAG);
}
and here I'm getting error "Can not resolve method show(android.app.FragmentManager, java.lang.String).
All these because my DialogFragment is from androidx.fragment.app package when Activity's getFragmentManager() returns FragmentManager from android.app package.
I see 2 options to solve this.
- Change dependency of
DialogFragment, and use the one fromandroid.app - Change
myMethod()signature to receiveAppCompatActivity(from androidx) instead ofActivityand callgetSupportedFragmentManager().
First solution is not good as I want to keep using androidx classes everywhere possible. Second is also has drawbacks despite of AppCompatAcivitity is a best practice.
Question is : Is there a way to keep using androidx dependency and having Activity type parameter inside myMethod() ?
You should use
FragmentActivity(from androidx) instead ofActivityas the argument type inmyMethod()and callgetSupportFragmentManager()to get theFragmentManageron it. This should solve your problem.