From 53244870e91e8add48f3bade60bc96b5f9929b3b Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Fri, 9 Oct 2020 14:56:26 -0700 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/15812: Check for a null context during onScanResult --- .../java/org/mozilla/fenix/settings/PairFragment.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt index 401a4e3b9c..cc398781d0 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/PairFragment.kt @@ -37,6 +37,15 @@ class PairFragment : Fragment(R.layout.fragment_pair), UserInteractionHandler { requestPermissions(permissions, REQUEST_CODE_CAMERA_PERMISSIONS) }, onScanResult = { pairingUrl -> + // By the time we get a scan result, we may not be attached to the context anymore. + // See https://github.com/mozilla-mobile/fenix/issues/15812 + if (context == null) { + findNavController().popBackStack( + R.id.turnOnSyncFragment, + false + ) + return@QrFeature + } requireComponents.services.accountsAuthFeature.beginPairingAuthentication( requireContext(), pairingUrl @@ -53,7 +62,7 @@ class PairFragment : Fragment(R.layout.fragment_pair), UserInteractionHandler { @Suppress("Deprecation") vibrator.vibrate(VIBRATE_LENGTH) } - findNavController(this@PairFragment).popBackStack( + findNavController().popBackStack( R.id.turnOnSyncFragment, false )