'Go back to a Fragment from a PreferenceFragment

Code in the PreferenceFragment (android.preference.PreferenceFragment)

getActivity().getFragmentManager().beginTransaction()
            .replace(R.id.container, new MyFragment())
            .commit();

MyFragment is an androidx.fragment.app.Fragment.

The errors says "incompatible types: MyFragment cannot be converted to Fragment"

Is there a simple solution to fix this problem without changing the PreferenceFragment?

Thanks a lot!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source