From 65426fff19a84918e6de6ea8f1bcf8e57ae5a053 Mon Sep 17 00:00:00 2001 From: Mike Wong Date: Wed, 13 Oct 2021 09:57:06 +0200 Subject: [PATCH] Check if fragment is added before accessing viewLifecycleOwner --- .../wallet/homescreen/pager/TransferCodePagerFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/homescreen/pager/TransferCodePagerFragment.kt b/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/homescreen/pager/TransferCodePagerFragment.kt index 9f5fbebd..7343c493 100644 --- a/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/homescreen/pager/TransferCodePagerFragment.kt +++ b/wallet/src/main/java/ch/admin/bag/covidcertificate/wallet/homescreen/pager/TransferCodePagerFragment.kt @@ -87,8 +87,10 @@ class TransferCodePagerFragment : Fragment(R.layout.fragment_transfer_code_pager // Before that call, the fragment root will be measured with the entire screen size and not the reduced viewpager size view.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { - vaccinationHintViewModel.displayVaccinationHint.observe(viewLifecycleOwner) { shouldDisplayVaccinationHint -> - displayVaccinationHint(shouldDisplayVaccinationHint) + if (isAdded) { + vaccinationHintViewModel.displayVaccinationHint.observe(viewLifecycleOwner) { shouldDisplayVaccinationHint -> + displayVaccinationHint(shouldDisplayVaccinationHint) + } } view.viewTreeObserver.removeOnGlobalLayoutListener(this)