Anki-android: Android 9: crash when opening note editor

Created on 23 Feb 2019  路  29Comments  路  Source: ankidroid/Anki-Android

Reproduction Steps

(Edit: please change "note editor" in title to "card editor")

  1. Review a card
  2. Chose "edit note" from the menu
  3. Click on the card name (last row below the tags) to go to the card editor
Expected Result

Card editor opens

Actual Result

App crashes. I can't open the card editor from the edit note screen. I need to open it from the main menu.
On android 8 I never had problems to open the card editor during reviews, these crashes are new in Android 9.

Debug info

AnkiDroid Version = 2.9alpha66

Android Version = 9

ACRA UUID = f2d13677-d957-460e-9f8e-33ca6f832c17

Refer to the support page if you are unsure where to get the "debug info".

Research

Enter an [ x ] character to confirm the points below:

[ ] I have read the support page and am reporting a bug or enhancement request specific to AnkiDroid

[ ] I have checked the manual and the FAQ and could not find a solution to my issue

[ ] I have searched for similar existing issues here and on the user forum

Bug Help Wanted Needs Triage

All 29 comments

I just tried this on Android 9 - in a review, I selected to edit the note, then inside the edit note screen I tapped the card button at the bottom and it opened fine. This is the behaviour I'd expect if the (infamous, to me) card template editor issue fixed in #5151 has bitten you producing a (luckily not data-destructive) corruption and you need to run a database check

Great, thanks! Database check solved that issue.

Separately - just hijacking this for a moment - I'd urge you to look for a template + font combination that worked well on modern Chrome - fighting Google on that upgrade is going to be really difficult and in the end will leave you less secure as well. The reponse we received from them on the original bug was basically that we were using terrible fonts (paraphrasing, but the same strength of feeling was there). If you could tease apart exactly which element caused the slowdown, you might be able to stay up to date with the WebViews...

Sorry, this issue is still present. After the database check I could open the card editor during reviews from most of my decks. But some decks still cause the app to crash.

Since I use almost the same templates for all of my decks and they all use Javascript from the same external file, I don't know why some decks cause problems and others don't.

Anything else I can try to prevent the app crashes (it crashes in the edit note screen and then re-opens immediately into the deck view.)

com.afollestad.materialdialogs.MaterialDialog$DialogException: Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
at com.afollestad.materialdialogs.MaterialDialog.show(MaterialDialog.java:466)
at com.ichi2.anki.ReadText$2.run(ReadText.java:139)
at android.os.Handler.handleCallback(Handler.java:874)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:198)
at android.app.ActivityThread.main(ActivityThread.java:6729)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Hmmm.

Code there says this:


        // Show the dialog after short delay so that user gets a chance to preview the card
        final Handler handler = new Handler();
        final int delay = 500;
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                builder.build().show();
            }
        }, delay);

Could you try doing whatever you are doing...more...slowly? I wonder if this is the actual crash or a different thing, but if this is the crash it's because there's a delay here before showing the dialog, then when the dialog attempts to pop up, its window is gone so it crashes.

Thanks for the fast reply. Maybe that's a different thing, I don't see a message that a report was sent when the app crashes and reloads.
Also, I tried it again _very_ slowly but as soon as I tap the card name, the app crashes.
In other decks, I can tap the card name as fast as I can and it opens the card editor.

Again: this problem started with Android 9. On Android 8 I was editing cards through this way all the time and the app never crashed.

Hmm. I'd try a db check one more time even though I admit it is mostly superstition at this point, then if you could maybe export just one deck that has the problem and attach it here (you'll have to rename the .apkg to .zip so github will take it, and it's just a zip anyway really) I can try to reproduce. I have Pie emulators and my main real device is Pie too now.

This is an export from one of the troublesome decks without media from Ankidroid:
Japanese_10k.apkg.zip

Later I can upload a deck with media files from Anki desktop

And one more question: after I exported this deck, Ankidroid now wants a full sync. What did the export change in my collection so that a full sync becomes necessary?

That is unexpected! There is nothing about an export that should cause a full sync, and I know from previous discussion your collection is large enough that this is a real pain. Did you sync after the database check and corruption fix? Because if you haven't synced yet, that is likely it - during the integrity check if any problems are found it marks the collection as needing a sync since the fixes in that routine are outside of what a normal sync would expect and it could otherwise re-propagate corruption

dang, I imported that deck in an Android 9 emulator and my device and I can't reproduce it. It must have something to do with your specific configuration but unfortunately it's using so many features at once I couldn't guess what it is. I have a hunch it's related to text to speech somehow but I can't even justify the hunch. All I can recommend is to maybe get a deck down to just one card that does it (maybe in a parallel build so you're not messing with your main collection - even if it's a little behind - I think those are on alpha 55 or 56 still) - and try toggling TTS off?

Thanks for your answers. About the full sync: I synced right before the export and I didn't do anything on AnkiDroid after the export. My sync settings are "every 10 minutes" so the next time I opened Ankidroid it tried to sync and realized some mismatches so that it now wants the full sync. Yes, unexpected indeed. So much pain since I updated to Android 9 :-(

Now I see what happened: Ankidroid deleted my option group for the exported deck!! That's why the full sync became necessary. I guess I need to open a new issue "Ankidroid deletes deck option group after export" now?

Edit: Sorry, I was too fast. The option group is still there. The exported deck just changed to the "default" option group and all cards became re-sorted. Seems that I can just switch back to the original option group. Anyway, open new issue "option group changes after export"?

Indeed, that sounds serious - if you can open that I'll try to at least reproduce as soon as I can

Back to the main topic: in the uploaded deck the app only crashes when the reverse card is being reviewed. If card1 is being reviewed I can tap on the card name (both card names work) and the card editor opens just fine. Doing the same when card2 is being reviewed, the app crashes.

I turned off TTS and I deleted all front card contents already (just plain text left), but still the app crashes every time.

So TTS might not be causing this. I wonder why card1 doesn't crash?

@mikehardy You said "...fighting Google on that upgrade is going to be really difficult..." earlier and now I understand what you meant.

I made a factory reset of my phone since I was sure I could solve all the issues with my Ankidroid decks and pie by going back to oreo.

But that's not possible with a factory reset! The system remains Android 9. In previous versions I could go back to the original version with a factory reset, but with Pie it is not possible. I didn't know that, so I spent some horrible 20 hours with a complete new setup of my phone.

With the result that nothing changed. All issues remain. Ankidroid keeps crashing when opening the card editor and the performance with Chrome 70+ drives me insane.

One more thing: The first time sync of Ankidroid (download from server) took 6 hours and almost a whole battery charge. Also it doesn't work in the background, the download just stops if Ankidroid is not the foreground app. I noticed that a couple of times before and I highly recommend to show a message for that. I'll open an issue for that if it doesn't exist yet.

What I learned:
1) never change a running system
2) buy iPhone next time

The pie upgrade was a big one because they repartioned storage. Future versions should be like previous - this was project treble landing. I still have hope things can work for you. I just haven't had time to reproduce since your last post and I did not try card2 so maybe I can see it. I can't recommend iPhone to anyone that customizes like you do 馃槈. Make sure ankidroid is exempt from battery optimization for background execution

The first time sync of Ankidroid (download from server) took 6 hours and almost a whole battery charge.

If you have a lot of media files, then I strongly recommend bringing your media collection over manually from Anki Desktop using .apkg file, rather than relying on the media sync (which will be very slow as you described)

Make sure ankidroid is exempt from battery optimization for background execution

No battery optimization for Ankidroid, no energy saving mode. Still the download stops when Ankidroid is not the foreground app. I experienced this a couple of times before when I added maybe 1000 - 5000 images. The sync just stops when the app is in the background. At least there should be a message "downloading a large amount of files requires Ankidroid to run in foreground" or "More than 1000 new files on the server. Continue sync? This may take several hours." so that users can cancel manually and use an external memory instead to copy the files.

I tried again today on OnePlus5 + Android9 and the ANdroid9 emulator with the uploaded collection, taking care to attempt an edit on both card templates, and I was unable to reproduce. There may be something else to the configuration that is apparent in the preferences file. That file contains information that is user-identifiable, like the AnkiWeb user/pass, but if it were possible to upload it after scrubbing any personally identifiable information out that may show the problem - maybe it's TTS or something, I dunno.

Do you mean the prefs.db in the main folder of Anki desktop? Or is there a separate one for Ankidroid? I don't find any credentials there, what should I delete?

I just wonder why that problem never exists in Android 8. It started with Android 9 without any changes on the collection.

If you use a file exolirer and look in the app data directory there is a preference xml file on Android. They may have changed the way TTS (or something else you use) behaves under the udentic API. Google does that sometimes. If I use the same orefs I might be able to reproduce

It seems your guess was correct. Actually the app crashes everytime when I open the card editor from a card that starts with TTS (usually cards 2 or 3). It never crashes when I open the card editor from a card that doesn't start with TTS.
I exported one of my smaller decks where the app crashes when I open the card editor from cards 2 and 3. Could you check it out if it crashed on your Android 9 device?
Takoboto.zip

Also strange: in Anki desktop (!) the card editor always crashes when I'm scrolling through the contents in the "answer" field. Seems that Anki doesn't like my JS although the code has no errors. But that might not be related since my other decks don't crash in Anki desktop but in AnkiDroid.

Sorry I haven't had time to check this - I'm really swamped with work at the moment. I saved in my mailbox and can at least switch up the tags now. Thanks especially for providing a collection that should reproduce it

Just as an update: I installed your parallel build with the "browsable" category and imported the uploaded deck. Same there. Even with a fresh install/profile the deck crashes when opening the card editor.

I actually think this is the same as #5138 but I haven't done triage. They should be at least be given a quick look at the same time

Interesting: this bug does not only occur during reviews but also in the card browser!

1) open card browser
2) search a note with at least two cards
3) tap on the first found card (forward card), then tap on the card name to open the card editor -> it opens as expected
4) go back to the search results and tap on the second found card (reverse card), then tap on the card name to open the card editor -> Ankidroid crashes!

This is super strange to me. I don't think that TTS can still be the cause for this issue since the webview is not used in the card browser and TTS doesn't need to be initialized.

Since 2.9alpha74 the app doesn't crash anymore. Seems that you found the cause of the bug?
There where quite a few Ankidroid updates recently, so I can't say which version exactly fixed the bug. But 2.9alpha71 was crashing every time I opened the note editor from a card that starts with TTS.

With 2.9alpha74 the card editor opens as expected (both during reviews and in the browser).

Interesting: opening the card editor from the same note, it opens instantly from "card1" (no TTS) but takes around 2 seconds to open it from "card2" (with TTS, the card that previously caused the crash) of the same note.

During these 2 seconds AnkiDroid previously crashed. Now it just waits two seconds and then opens the card editor as expected.

(I'll close this and report back if there occur any crashes in the future)

Nice! I guess it was the support library update from Google that fixed it then!

Was this page helpful?
0 / 5 - 0 ratings