Avoid loading collection if finishing() == true #4997
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was proposed as a fix for #4987 but that issue is being fixed
in a defense-in-depth fashion as this is a threading change and
harder to reason about
This PR is a result of discussion here - 96ed621#r30675818
This was the reasoning for the change:
AnkiActivity.onStart() goes off UI thread to load the collection
Previewer and AbstractFlashCardViewer.onLoadCollection() start to do all sorts of UI updates but nothing is in a state to display and you had an invalid state - this is literally the Crash in AbstractFlashCardViewer.onCollectionLoaded() ArrayIndexOutOfBoundsException #4987 crash stack trace, fully reproducible - in current alpha just get the CardBrowser to an empty list state and pick Preview from options menu
So here instead of loading the collection in to an Activity that signaled they were finishing (implying it's time to get to work even though we said we don't want to work), we demur and e.g. Previewer safely goes away. I could have protected Previewer.onLoadCollection() and AbstractFlashCardViewer.onLoadCollection() so they were safe even if finish() was called, but there may be things like this in any AnkiActivity subclass and since I think the general idea of "isFinishing()?, okay, forget it" seemed correct it would protect everyone at once