Fix crash in BalancesFragment.
- The crash was happening in a very weird scenario, but it was good because it forced us to search an alternative to update the BalancesFragment when the user navigates back to the HomeFragment. The solution was to use the childFragmentManager instead of the fragmentManager to create the PagerAdapter used in the ViewPager that displays the BalancesFragment. Basically, because we are using nested fragments we need to use the childFragmentManager instead of just the fragmentManager, to use the correct LyfeCycle events.
This commit is contained in:
parent
6482b31971
commit
31073e2acf
3 changed files with 1 additions and 17 deletions
|
@ -43,12 +43,4 @@ class BalancesFragment: Fragment() {
|
||||||
balancesAdapter.replaceAll(balancesDetails)
|
balancesAdapter.replaceAll(balancesDetails)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
|
||||||
super.setUserVisibleHint(isVisibleToUser)
|
|
||||||
if (isVisibleToUser) {
|
|
||||||
// TODO find a better way to recreate the fragment, that does it only when the theme has been changed
|
|
||||||
fragmentManager?.beginTransaction()?.detach(this)?.attach(this)?.commit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -112,7 +112,7 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure ViewPager with PagerAdapter and TabLayout to display the Balances/NetWorth section
|
// Configure ViewPager with PagerAdapter and TabLayout to display the Balances/NetWorth section
|
||||||
val pagerAdapter = PagerAdapter(fragmentManager!!)
|
val pagerAdapter = PagerAdapter(childFragmentManager)
|
||||||
viewPager.adapter = pagerAdapter
|
viewPager.adapter = pagerAdapter
|
||||||
tabLayout.setupWithViewPager(viewPager)
|
tabLayout.setupWithViewPager(viewPager)
|
||||||
// Set the pie chart icon for the third tab
|
// Set the pie chart icon for the third tab
|
||||||
|
|
|
@ -17,12 +17,4 @@ class NetWorthFragment: Fragment() {
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_net_worth, container, false)
|
return inflater.inflate(R.layout.fragment_net_worth, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
|
||||||
super.setUserVisibleHint(isVisibleToUser)
|
|
||||||
if (isVisibleToUser) {
|
|
||||||
// TODO find a better way to recreate the fragment, that does it only when the theme has been changed
|
|
||||||
fragmentManager?.beginTransaction()?.detach(this)?.attach(this)?.commit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue