Skip to content

Commit

Permalink
Fix for PdfReaderViewModel.onStop NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima-Android committed Dec 25, 2024
1 parent ec18fac commit 00950b1
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,13 @@ class PdfReaderViewModel @Inject constructor(
}

fun onStop(isChangingConfigurations: Boolean) {
if (!this::pdfFragment.isInitialized || this.pdfFragment.document == null) {
//If pdfFragment is not yet initialized and onStop is called the most likely cause is that user has returned to the app after a while hence ViewModel was deinitialized and then user either very quickly:
//1. Navigated to some other screen from PdfReaderScreen screen
//2. Navigated back from the PdfReaderScreen to AllItemsScreen
//In either of those cases the ViewModel can be caught in the process of re-initializing pdfFragment and since we are navigating away from PdfReaderScreen the execution of onStop method's contents is no longer needed
return
}
pdfDocumentBeforeFragmentDestruction = pdfFragment.document!!
submitPendingPage(pdfUiFragment.pageIndex)
if (isChangingConfigurations) {
Expand Down

0 comments on commit 00950b1

Please sign in to comment.