diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt index 5d800f5cef..a6fe86d6af 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt @@ -257,9 +257,10 @@ class KiwixReaderFragment : CoreReaderFragment() { when (restoreOrigin) { FromExternalLaunch -> { coreReaderLifeCycleScope?.launch { + if (!isAdded) return@launch val settings = - requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0) - val zimReaderSource = fromDatabaseValue(settings.getString(TAG_CURRENT_FILE, null)) + activity?.getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0) + val zimReaderSource = fromDatabaseValue(settings?.getString(TAG_CURRENT_FILE, null)) if (zimReaderSource?.canOpenInLibkiwix() == true) { if (zimReaderContainer?.zimReaderSource == null) { openZimFile(zimReaderSource, isFromManageExternalLaunch = true) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index 3b16565594..d319948be5 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -1220,6 +1220,7 @@ abstract class CoreReaderFragment : override fun onDestroyView() { super.onDestroyView() try { + coreReaderLifeCycleScope?.cancel() readerLifeCycleScope?.cancel() readerLifeCycleScope = null } catch (ignore: Exception) {