Remove deprecated function and prevent errors in case of a null fragment name
This commit is contained in:
parent
bd6b96d09d
commit
990a354229
@ -71,23 +71,25 @@ class SettingsActivity : AppCompatActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreferenceStartFragment(
|
override fun onPreferenceStartFragment(
|
||||||
caller: PreferenceFragmentCompat,
|
caller: PreferenceFragmentCompat,
|
||||||
pref: Preference
|
pref: Preference
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
val fragmentClassName = pref.fragment ?: return false
|
||||||
|
|
||||||
// Instantiate the new Fragment
|
// Instantiate the new Fragment
|
||||||
val args = pref.extras
|
val args = pref.extras
|
||||||
val fragment = supportFragmentManager.fragmentFactory.instantiate(
|
val fragment = supportFragmentManager.fragmentFactory.instantiate(
|
||||||
classLoader,
|
classLoader,
|
||||||
pref.fragment
|
fragmentClassName
|
||||||
).apply {
|
).apply {
|
||||||
arguments = args
|
arguments = args
|
||||||
setTargetFragment(caller, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the existing Fragment with the new Fragment
|
// Replace the existing Fragment with the new Fragment
|
||||||
supportFragmentManager.beginTransaction()
|
supportFragmentManager.beginTransaction()
|
||||||
.replace(R.id.settings, fragment)
|
.replace(R.id.settings, fragment)
|
||||||
.addToBackStack(null)
|
.addToBackStack(null)
|
||||||
.commit()
|
.commit()
|
||||||
title = pref.title
|
title = pref.title
|
||||||
supportActionBar?.title = title
|
supportActionBar?.title = title
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user