ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.67k stars 2.24k forks source link

Reviewer / Previewer don't store/restore state on restart (switch to night view while using them to see) #4035

Closed timo-a closed 8 months ago

timo-a commented 8 years ago

1) go to Browser select preview on a card pull side bar in, switch to night mode ->crash

2) review card A pull side bar in, switch to night mode -> another card B is on top, card A has disappeared back into the deck

jeffreyj100 commented 8 years ago

Is it right to allow the user the option of swiping the nav menu and toggling night mode while on preview view, as edit note view does not have this option?

hssm commented 8 years ago

The way we restart activities when toggling night mode doesn't really work for the previewer (hierarchy and state are both lost). So unless we come up with a better way to do that in the future, I think the quick and easy solution to avoiding the crash is indeed to disable the nav drawer.

As for point 2 in the original issue, that is not what usually happens, so I don't know what is going on with that.

ospalh commented 8 years ago

@hssm: # 2: I see this from time to time. One way i think this can happen is when a learning card (card B) becomes due while you (re)view card A.

timo-a commented 8 years ago

@hssm I found a new way to produce the behaviour in point 2! You don't need new or red-because-wrong-answer cards. open deck get first card correct on second card switch to night mode

ukanuk commented 4 years ago

Just wanted to mention I'm still getting the behavior in point # 2. Generally I leave night mode on, but one of my cards has a stroke order diagram with black lines on a transparent background, which is practically invisible in night mode. Therefore I pull out the navigation drawer, turn off night mode --- and then am presented with different cards. So I end up having night mode disabled for a significant part of the review session, until that offending card reappears in the reviews.

Not a big deal at the end of the day, but it does take a little bit to get back in rhythm of review.

mikehardy commented 4 years ago

Switching to or from night mode causes a full app restart if I recall, yes. So pretty much any ephemeral state (like, current state of the reviewer activity) will be blown away. Not sure how I'd handle that but if there was a way to stuff info in a bundle for the activity and reload it, and someone followed through the control chain on night-mode switches, might be possible.

mikehardy commented 4 years ago

@ukanuk this should be fixed I think along with #5688 via #5693 ? But maybe reviewer needs a change too? Can you check the latest alphas to see if you reproduce

ukanuk commented 4 years ago

@mikehardy The issue is still present when toggling night mode, although I can swap between portrait/landscape on both reviewer and previewer without losing the current card.

This is with version 2.10alpha43, which I got from following directions at https://docs.ankidroid.org/manual.html#betaTesting to join the Google Play beta and also the ankidroidalphatesters google group.

mikehardy commented 4 years ago

@ukanuk sorry it is still happening but thanks a lot for checking that out and letting us know

github-actions[bot] commented 4 years ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

mikehardy commented 3 years ago

This is a special case of #3654 - please refer to that issue for easier reproduction than night mode toggles (specifically: "don't keep activities" developer setting in phone preferences

david-allison commented 3 years ago

This is a more complex issue than initially appears.

The issue is that the card is not saved onSaveInstanceState, to work around this, we refresh the next card from the scheduler onCollectionLoaded:

https://github.com/ankidroid/Anki-Android/blob/a316393d837034884fd4ceacef44572111f93ea5/AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java#L287

In this time, the "next" card from the scheduler may have changed. This causes a different card to be displayed

As for solutions:

  1. Save the card id and restore that instead of going through the scheduler ❌
  2. Modify the scheduler to add a getCard(id) method ❌
  3. Serialize and restore the card to the instance state

1

Not currently feasible. The scheduler makes modifications to the card object inside sched.getCard. This may be only AnkiDroid-related code

2

Not currently feasible. Arbitrary card retrieval not supported by the Rust scheduler: https://github.com/ankitects/anki/blob/main/proto/anki/scheduler.proto#L15

3

dae commented 3 years ago

That should not be necessary in the v3 scheduler; getQueuedCards() is designed to be idempotent under most circumstances.