Fix FragmentStateAdapter recreates Fragments

This commit is contained in:
100kg-5km 2025-02-08 08:20:37 +08:00
parent cc91eaa2af
commit 061fa063d6
2 changed files with 4 additions and 1 deletions

View file

@ -69,6 +69,7 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
override fun onDestroyView() {
super.onDestroyView()
binding = null
commandClient.disconnect()
}
private var displayed = false

View file

@ -40,10 +40,11 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
return binding.root
}
private val adapter by lazy { Adapter(this) }
private fun onCreate() {
val activity = activity ?: return
val binding = binding ?: return
binding.dashboardPager.adapter = Adapter(this)
binding.dashboardPager.adapter = adapter
binding.dashboardPager.offscreenPageLimit = Page.values().size
activity.serviceStatus.observe(viewLifecycleOwner) {
when (it) {
@ -107,6 +108,7 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
super.onDestroyView()
mediator?.detach()
mediator = null
binding?.dashboardPager?.adapter = null
binding = null
}