From bd297b392d460da86d886d25c1645bfa11e2e88f Mon Sep 17 00:00:00 2001 From: Colin Lee Date: Mon, 13 May 2019 10:59:05 -0500 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/2449: App crashes when switching themes (https://github.com/mozilla-mobile/fenix/pull/2450) --- .../org/mozilla/fenix/home/HomeFragment.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 953298e087..be849e957b 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -167,17 +167,20 @@ class HomeFragment : Fragment(), CoroutineScope { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - val state = sessionControlComponent.stateObservable.blockingFirst() - outState.putParcelableArrayList( - KEY_TABS, - ArrayList(state.tabs) - ) - outState.putParcelableArrayList( - KEY_COLLECTIONS, - ArrayList(state.collections) - ) - val modeInt = if (state.mode is Mode.Private) 0 else 1 - outState.putInt(KEY_MODE, modeInt) + // This can get called before onCreateView, before the component is defined + view?.let { + val state = sessionControlComponent.stateObservable.blockingFirst() + outState.putParcelableArrayList( + KEY_TABS, + ArrayList(state.tabs) + ) + outState.putParcelableArrayList( + KEY_COLLECTIONS, + ArrayList(state.collections) + ) + val modeInt = if (state.mode is Mode.Private) 0 else 1 + outState.putInt(KEY_MODE, modeInt) + } } override fun onViewStateRestored(savedInstanceState: Bundle?) {