Remove deprecated function and prevent errors in case of a null fragment name

This commit is contained in:
davidoskky 2023-09-11 21:09:03 +02:00
parent bd6b96d09d
commit 990a354229

View File

@ -71,23 +71,25 @@ class SettingsActivity : AppCompatActivity(),
}
override fun onPreferenceStartFragment(
caller: PreferenceFragmentCompat,
pref: Preference
caller: PreferenceFragmentCompat,
pref: Preference
): Boolean {
val fragmentClassName = pref.fragment ?: return false
// Instantiate the new Fragment
val args = pref.extras
val fragment = supportFragmentManager.fragmentFactory.instantiate(
classLoader,
pref.fragment
classLoader,
fragmentClassName
).apply {
arguments = args
setTargetFragment(caller, 0)
}
// Replace the existing Fragment with the new Fragment
supportFragmentManager.beginTransaction()
.replace(R.id.settings, fragment)
.addToBackStack(null)
.commit()
.replace(R.id.settings, fragment)
.addToBackStack(null)
.commit()
title = pref.title
supportActionBar?.title = title
return true