Skip to content

Commit

Permalink
fix: ignore shared deck download if lifecycle teardown has begun
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehardy authored and BrayanDSO committed Nov 25, 2024
1 parent 16e8561 commit 5220da8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/anki/SharedDecksActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ class SharedDecksActivity : AnkiActivity() {
webView.loadUrl(resources.getString(R.string.shared_decks_url))
webView.webViewClient = WebViewClient()
webView.setDownloadListener { url, userAgent, contentDisposition, mimetype, _ ->
val sharedDecksDownloadFragment = SharedDecksDownloadFragment()
sharedDecksDownloadFragment.arguments = bundleOf(DOWNLOAD_FILE to DownloadFile(url, userAgent, contentDisposition, mimetype))

supportFragmentManager.commit {
add(R.id.shared_decks_fragment_container, sharedDecksDownloadFragment, SHARED_DECKS_DOWNLOAD_FRAGMENT).addToBackStack(null)
// If the activity/fragment lifecycle has already begun teardown process,
// avoid handling the download, as FragmentManager.commit will throw
if (!supportFragmentManager.isStateSaved) {
val sharedDecksDownloadFragment = SharedDecksDownloadFragment()
sharedDecksDownloadFragment.arguments = bundleOf(DOWNLOAD_FILE to DownloadFile(url, userAgent, contentDisposition, mimetype))
supportFragmentManager.commit {
add(R.id.shared_decks_fragment_container, sharedDecksDownloadFragment, SHARED_DECKS_DOWNLOAD_FRAGMENT).addToBackStack(null)
}
}
}

Expand Down

0 comments on commit 5220da8

Please sign in to comment.