Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadTokenException: Unable to add window -- token ... is not valid; is your activity running? #17389

Open
Tracked by #17370
david-allison opened this issue Nov 7, 2024 · 1 comment
Labels

Comments

@david-allison
Copy link
Member

david-allison commented Nov 7, 2024

https://ankidroid.org/acra/app/1/bug/253690/report/a13864c6-cfaa-48ff-8e35-690b4ac07654

android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@8f67d0f is not valid; is your activity running?
	at android.view.ViewRootImpl.setView(ViewRootImpl.java:1771)
	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:564)
	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:170)
	at com.android.internal.view.TooltipPopup.show(TooltipPopup.java:140)
	at android.view.View.showTooltip(View.java:33335)
	at android.view.View.showHoverTooltip(View.java:33382)
	at android.view.View.$r8$lambda$27VXCdyLVNkujfByQKuywAc_nkI(Unknown Source)
	at android.view.View$$ExternalSyntheticLambda3.run(Unknown Source:2)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8810)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

logcat

--------- beginning of main
11-05 11:32:00.457 W/AnkiDroid(22972): Backend$checkMainThreadOp/ Op on UI thread: com.ichi2.anki.Reviewer.suspendNoteAvailable(SourceFile:58)
11-05 11:32:00.459 W/AnkiDroid(22972): Backend$checkMainThreadOp/ Op on UI thread: kotlin.io.CloseableKt.closeFinally(SourceFile:5)
11-05 11:32:00.470 W/AnkiDroid(22972): Backend$checkMainThreadOp/ Op on UI thread: com.ichi2.anki.Reviewer.buryNoteAvailable(SourceFile:58)
11-05 11:32:00.474 W/AnkiDroid(22972): Backend$checkMainThreadOp/ select 1 from cards where nid = ? and id != ? and queue >=  0 limit 1
11-05 11:32:00.474 W/AnkiDroid(22972): Backend$checkMainThreadOp/ Op on UI thread: com.ichi2.anki.Reviewer.buryNoteAvailable(SourceFile:58)
11-05 11:32:00.480 W/AnkiDroid(22972): Backend$checkMainThreadOp/ Op on UI thread: kotlin.io.CloseableKt.closeFinally(SourceFile:5)
11-05 11:32:00.788 I/AnkiDroid(22972): DeckPicker::onStop
11-05 11:32:00.789 I/AnkiDroid(22972): DeckPicker::StudyOptionsFragment::onStop
11-05 11:32:00.789 I/AnkiDroid(22972): DeckPicker::onSaveInstanceState
11-05 11:32:00.790 I/AnkiDroid(22972): DeckPicker::StudyOptionsFragment::onSaveInstanceState
11-05 11:32:02.731 I/AnkiDroid(22972): Reviewer::onPause
11-05 11:32:02.731 I/AnkiDroid(22972): stop: automatically show answer
11-05 11:32:02.731 I/AnkiDroid(22972): stop: automatically show question
11-05 11:32:03.315 I/AnkiDroid(22972): Reviewer::onStop
11-05 11:32:03.318 I/AnkiDroid(22972): Reviewer::onSaveInstanceState
11-05 12:59:24.187 I/AnkiDroid(14416): Timber config: PRODUCTION
11-05 12:59:24.188 I/AnkiDroid(14416): initialize()
11-05 12:59:25.034 I/AnkiDroid(14416): Not participating in analytics sample (sample percentage vs random: 10 17)
11-05 12:59:25.034 I/AnkiDroid(14416): setOptIn(): from false to true
11-05 12:59:25.034 I/AnkiDroid(14416): Participating in analytics sample (sample percentage vs random: 10 8)
11-05 12:59:25.058 I/AnkiDroid(14416): Creating notification channel with id/name: General Notifications/AnkiDroid
11-05 12:59:25.059 I/AnkiDroid(14416): Creating notification channel with id/name: Synchronization/Sincronização
11-05 12:59:25.060 I/AnkiDroid(14416): Creating notification channel with id/name: Global Reminders/Cartões pendentes
11-05 12:59:25.061 I/AnkiDroid(14416): Creating notification channel with id/name: Deck Reminders/Lembretes
11-05 12:59:25.072 I/AnkiDroid(14416): AnkiDroidApp: Starting Services
11-05 12:59:25.073 W/AnkiDroid(14416): AnkiDroidApp/ BootService - unexpected action received, ignoring: null
11-05 12:59:25.104 I/AnkiDroid(14416): IntentHandler::onCreate
11-05 12:59:25.105 I/AnkiDroid(14416): Setting theme to LIGHT
11-05 12:59:25.156 I/AnkiDroid(14416): Launching DeckPicker
11-05 12:59:25.413 I/AnkiDroid(14416): AnkiDroid Version = 2.19.1 (6953d60532ee2762d29b06fd1d76e69203ad8455)
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Backend Version = 0.1.43-anki24.06.3 (24.06.3 d678e39350a2d243242a69f4e22f5192b04398f2)
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Android Version = 13 (SDK 33)
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): ProductFlavor = play
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Manufacturer = samsung
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Model = SM-P615
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Hardware = exynos9611
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Webview User Agent = Mozilla/5.0 (Linux; Android 13; SM-P615 Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/130.0.6723.86 Safari/537.36
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): ACRA UUID = 8c2c8f87-be1e-4857-97fe-945a500df6de
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): FSRS = 0.6.4 (Enabled: null)
11-05 12:59:25.413 I/AnkiDroid(14416): 
11-05 12:59:25.413 I/AnkiDroid(14416): Crash Reports Enabled = true
11-05 12:59:25.427 I/AnkiDroid(14416): Setting theme to LIGHT
11-05 12:59:25.439 I/AnkiDroid(14416): DeckPicker::onCreate
11-05 12:59:25.613 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:25.613 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:25.613 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:25.613 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:25.646 I/AnkiDroid(14416): (Re)opening Database: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1/collection.anki2
11-05 12:59:25.692 I/AnkiDroid(14416): AnkiDroid is being updated and a collection already exists.
11-05 12:59:25.692 I/AnkiDroid(14416): Current AnkiDroid version: 321901300
11-05 12:59:25.692 I/AnkiDroid(14416): Previous AnkiDroid version: 321804300
11-05 12:59:25.693 I/AnkiDroid(14416): Running preference upgrade: i
11-05 12:59:25.695 I/AnkiDroid(14416): upgrading preference version to '19'
11-05 12:59:25.695 I/AnkiDroid(14416): Updated preferences with no integrity check - restarting activity
11-05 12:59:25.704 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:25.704 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:25.704 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:25.704 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:25.721 I/AnkiDroid(14416): DeckPicker::onStart
11-05 12:59:25.722 I/AnkiDroid(14416): DeckPicker::a8::onAttach
11-05 12:59:25.722 I/AnkiDroid(14416): DeckPicker::a8::onCreate
11-05 12:59:25.722 I/AnkiDroid(14416): onCreateView()
11-05 12:59:25.804 I/AnkiDroid(14416): configureToolbarInternal()
11-05 12:59:25.858 I/AnkiDroid(14416): DeckPicker::a8::onViewCreated
11-05 12:59:25.859 I/AnkiDroid(14416): DeckPicker::a8::onStart
11-05 12:59:25.937 I/AnkiDroid(14416): DeckPicker::onResume
11-05 12:59:25.946 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:25.946 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:25.946 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:25.947 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:25.953 I/AnkiDroid(14416): DeckPicker::a8::onResume
11-05 12:59:25.976 I/AnkiDroid(14416): DeckPicker::onPause
11-05 12:59:25.977 I/AnkiDroid(14416): DeckPicker::a8::onPause
11-05 12:59:25.978 I/AnkiDroid(14416): DeckPicker::onStop
11-05 12:59:25.979 I/AnkiDroid(14416): DeckPicker::a8::onStop
11-05 12:59:25.986 I/AnkiDroid(14416): DeckPicker::onSaveInstanceState
11-05 12:59:25.987 I/AnkiDroid(14416): DeckPicker::a8::onSaveInstanceState
11-05 12:59:25.989 I/AnkiDroid(14416): DeckPicker::onDestroy
11-05 12:59:25.990 I/AnkiDroid(14416): DeckPicker::a8::onViewDestroyed
11-05 12:59:25.991 I/AnkiDroid(14416): DeckPicker::a8::onDestroy
11-05 12:59:25.991 I/AnkiDroid(14416): DeckPicker::a8::onDetach
11-05 12:59:26.005 I/AnkiDroid(14416): Setting theme to LIGHT
11-05 12:59:26.010 I/AnkiDroid(14416): DeckPicker::onCreate
11-05 12:59:26.010 I/AnkiDroid(14416): DeckPicker::a8::onAttach
11-05 12:59:26.010 I/AnkiDroid(14416): DeckPicker::a8::onCreate
11-05 12:59:26.050 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:26.050 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:26.050 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:26.051 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:26.051 I/AnkiDroid(14416): AnkiDroid is being updated and a collection already exists.
11-05 12:59:26.051 I/AnkiDroid(14416): Current AnkiDroid version: 321901300
11-05 12:59:26.051 I/AnkiDroid(14416): Previous AnkiDroid version: 321901300
11-05 12:59:26.051 I/AnkiDroid(14416): Displaying new features
11-05 12:59:26.075 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:26.075 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:26.075 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:26.075 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:26.088 I/AnkiDroid(14416): DeckPicker::onStart
11-05 12:59:26.088 I/AnkiDroid(14416): onCreateView()
11-05 12:59:26.122 I/AnkiDroid(14416): configureToolbarInternal()
11-05 12:59:26.139 I/AnkiDroid(14416): DeckPicker::a8::onViewCreated
11-05 12:59:26.141 I/AnkiDroid(14416): DeckPicker::a8::onAttach
11-05 12:59:26.141 I/AnkiDroid(14416): DeckPicker::a8::onCreate
11-05 12:59:26.142 I/AnkiDroid(14416): onCreateView()
11-05 12:59:26.175 I/AnkiDroid(14416): configureToolbarInternal()
11-05 12:59:26.190 I/AnkiDroid(14416): DeckPicker::a8::onViewCreated
11-05 12:59:26.191 I/AnkiDroid(14416): DeckPicker::a8::onViewDestroyed
11-05 12:59:26.191 I/AnkiDroid(14416): DeckPicker::a8::onDestroy
11-05 12:59:26.191 I/AnkiDroid(14416): DeckPicker::a8::onDetach
11-05 12:59:26.192 I/AnkiDroid(14416): DeckPicker::a8::onStart
11-05 12:59:26.199 I/AnkiDroid(14416): DeckPicker::onResume
11-05 12:59:26.204 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:26.204 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:26.204 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:26.204 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:26.207 I/AnkiDroid(14416): DeckPicker::a8::onResume
11-05 12:59:26.527 I/AnkiDroid(14416): DeckPicker::onPause
11-05 12:59:26.527 I/AnkiDroid(14416): DeckPicker::a8::onPause
11-05 12:59:26.604 I/AnkiDroid(14416): Setting theme to LIGHT
11-05 12:59:26.612 I/AnkiDroid(14416): Info::onCreate
11-05 12:59:26.613 I/AnkiDroid(14416): Marked prefs as upgraded to latest version: 2.19.1
11-05 12:59:26.700 I/AnkiDroid(14416): ViewGroupUtils::setRenderWorkaround - using default / hardware rendering
11-05 12:59:26.730 I/AnkiDroid(14416): Info::onStart
11-05 12:59:26.734 I/AnkiDroid(14416): Info::onResume
11-05 12:59:26.782 I/AnkiDroid(14416): DeckPicker::onStop
11-05 12:59:26.783 I/AnkiDroid(14416): DeckPicker::a8::onStop
11-05 12:59:26.789 I/AnkiDroid(14416): DeckPicker::onSaveInstanceState
11-05 12:59:26.789 I/AnkiDroid(14416): DeckPicker::a8::onSaveInstanceState
11-05 12:59:26.792 I/AnkiDroid(14416): IntentHandler::onDestroy
11-05 12:59:43.928 I/AnkiDroid(14416): Home button pressed
11-05 12:59:43.939 I/AnkiDroid(14416): finishWithAnimation DEFAULT
11-05 12:59:43.962 I/AnkiDroid(14416): Info::onPause
11-05 12:59:44.007 I/AnkiDroid(14416): DeckPicker::onStart
11-05 12:59:44.008 I/AnkiDroid(14416): DeckPicker::a8::onStart
11-05 12:59:44.026 I/AnkiDroid(14416): No startup screens required
11-05 12:59:44.041 I/AnkiDroid(14416): DeckPicker::onResume
11-05 12:59:44.055 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:44.055 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:44.055 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:44.055 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:44.069 I/AnkiDroid(14416): DeckPicker::a8::onResume
11-05 12:59:44.208 I/AnkiDroid(14416): autoSync: starting foreground
11-05 12:59:44.220 I/AnkiDroid(14416): Updating deck list UI
11-05 12:59:58.656 W/AnkiDroid(14416): s3/ blocked main thread for 14429ms:
11-05 12:59:58.656 W/AnkiDroid(14416): P3.s3.j(SourceFile:61)
11-05 12:59:58.697 I/AnkiDroid(14416): configureToolbarInternal()
@david-allison david-allison changed the title https://ankidroid.org/acra/app/1/bug/253690/report/a13864c6-cfaa-48ff-8e35-690b4ac07654 BadTokenException: Unable to add window -- token ... is not valid; is your activity running? Nov 7, 2024
@david-allison david-allison added this to the 2.19.2 release milestone Nov 7, 2024
@mikehardy
Copy link
Member

This looks like some sort of race based on


11-05 12:59:26.792 I/AnkiDroid(14416): IntentHandler::onDestroy
11-05 12:59:43.928 I/AnkiDroid(14416): Home button pressed
11-05 12:59:43.939 I/AnkiDroid(14416): finishWithAnimation DEFAULT
11-05 12:59:43.962 I/AnkiDroid(14416): Info::onPause
11-05 12:59:44.007 I/AnkiDroid(14416): DeckPicker::onStart
11-05 12:59:44.008 I/AnkiDroid(14416): DeckPicker::a8::onStart
11-05 12:59:44.026 I/AnkiDroid(14416): No startup screens required
11-05 12:59:44.041 I/AnkiDroid(14416): DeckPicker::onResume
11-05 12:59:44.055 I/AnkiDroid(14416): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
11-05 12:59:44.055 I/AnkiDroid(14416): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
11-05 12:59:44.055 I/AnkiDroid(14416): scoped internal dir: /data/user/0/com.ichi2.anki/files
11-05 12:59:44.055 I/AnkiDroid(14416): isLegacyStorage(): false
11-05 12:59:44.069 I/AnkiDroid(14416): DeckPicker::a8::onResume
11-05 12:59:44.208 I/AnkiDroid(14416): autoSync: starting foreground
11-05 12:59:44.220 I/AnkiDroid(14416): Updating deck list UI
11-05 12:59:58.656 W/AnkiDroid(14416): s3/ blocked main thread for 14429ms:
11-05 12:59:58.656 W/AnkiDroid(14416): P3.s3.j(SourceFile:61)
11-05 12:59:58.697 I/AnkiDroid(14416): configureToolbarInternal()

I see:

1- app goes to background
2- app comes to foreground and auto-sync starts (while UI is frozen...?)
3- auto-sync completes and...
4- I assume (dangerous!) that onCollectionLoaded starts and does configureToolbarInternal
5- that process somehow adds a tooltip but the window token / view hierarchy stuff isn't setup correctly?

So configureToolbarInternal could be more resilient and tolerate this stuff, but the correct course is probably to see if the race can be altered to have a more predictable ordering

Just hypotheses though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants