Skip to content

Commit c26138c

Browse files
Fixed: Application crashes at first launch.
1 parent c33fc58 commit c26138c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,10 @@ class KiwixReaderFragment : CoreReaderFragment() {
257257
when (restoreOrigin) {
258258
FromExternalLaunch -> {
259259
coreReaderLifeCycleScope?.launch {
260+
if (!isAdded) return@launch
260261
val settings =
261-
requireActivity().getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
262-
val zimReaderSource = fromDatabaseValue(settings.getString(TAG_CURRENT_FILE, null))
262+
activity?.getSharedPreferences(SharedPreferenceUtil.PREF_KIWIX_MOBILE, 0)
263+
val zimReaderSource = fromDatabaseValue(settings?.getString(TAG_CURRENT_FILE, null))
263264
if (zimReaderSource?.canOpenInLibkiwix() == true) {
264265
if (zimReaderContainer?.zimReaderSource == null) {
265266
openZimFile(zimReaderSource, isFromManageExternalLaunch = true)

core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ abstract class CoreReaderFragment :
12201220
override fun onDestroyView() {
12211221
super.onDestroyView()
12221222
try {
1223+
coreReaderLifeCycleScope?.cancel()
12231224
readerLifeCycleScope?.cancel()
12241225
readerLifeCycleScope = null
12251226
} catch (ignore: Exception) {

0 commit comments

Comments
 (0)