mirror of
https://github.com/accelforce/Yuito
synced 2024-12-25 15:22:22 +01:00
fix crash when rotating screen in a preference dialog twice (#2083)
This commit is contained in:
parent
cd06b01d61
commit
6ebbe5f657
@ -21,6 +21,7 @@ import android.content.SharedPreferences
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.commit
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import com.keylesspalace.tusky.BaseActivity
|
import com.keylesspalace.tusky.BaseActivity
|
||||||
import com.keylesspalace.tusky.MainActivity
|
import com.keylesspalace.tusky.MainActivity
|
||||||
@ -58,7 +59,10 @@ class PreferencesActivity : BaseActivity(), SharedPreferences.OnSharedPreference
|
|||||||
setDisplayShowHomeEnabled(true)
|
setDisplayShowHomeEnabled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val fragment: Fragment = when (intent.getIntExtra(EXTRA_PREFERENCE_TYPE, 0)) {
|
val fragmentTag = "preference_fragment_$EXTRA_PREFERENCE_TYPE"
|
||||||
|
|
||||||
|
val fragment: Fragment = supportFragmentManager.findFragmentByTag(fragmentTag)
|
||||||
|
?: when (intent.getIntExtra(EXTRA_PREFERENCE_TYPE, 0)) {
|
||||||
GENERAL_PREFERENCES -> {
|
GENERAL_PREFERENCES -> {
|
||||||
setTitle(R.string.action_view_preferences)
|
setTitle(R.string.action_view_preferences)
|
||||||
PreferencesFragment.newInstance()
|
PreferencesFragment.newInstance()
|
||||||
@ -82,9 +86,9 @@ class PreferencesActivity : BaseActivity(), SharedPreferences.OnSharedPreference
|
|||||||
else -> throw IllegalArgumentException("preferenceType not known")
|
else -> throw IllegalArgumentException("preferenceType not known")
|
||||||
}
|
}
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction()
|
supportFragmentManager.commit {
|
||||||
.replace(R.id.fragment_container, fragment)
|
replace(R.id.fragment_container, fragment, fragmentTag)
|
||||||
.commit()
|
}
|
||||||
|
|
||||||
restartActivitiesOnExit = intent.getBooleanExtra("restart", false)
|
restartActivitiesOnExit = intent.getBooleanExtra("restart", false)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user