[BUG] showDeckPickerContextMenu: Can not perform this action after onSaveInstanceState
https://ankidroid.org/acra/app/1/bug/394505/report/f1a7bdde-a2ae-46b9-9c22-6ddd27b27ee9
2.24alpha13
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at androidx.fragment.app.FragmentManager.checkStateLoss(FragmentManager.java:1862)
at androidx.fragment.app.FragmentManager.enqueueAction(FragmentManager.java:1902)
at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:342)
at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:306)
at androidx.fragment.app.DialogFragment.show(DialogFragment.java:519)
at com.ichi2.anki.utils.DialogKt.showDialogFragmentImpl(Dialog.kt:45)
at com.ichi2.anki.utils.ext.FragmentActivityKt.showDialogFragment$lambda$0(FragmentActivity.kt:44)
at android.app.Activity.runOnUiThread(Activity.java:7068)
at com.ichi2.anki.utils.ext.FragmentActivityKt.showDialogFragment(FragmentActivity.kt:43)
at com.ichi2.anki.DeckPicker$showDeckPickerContextMenu$1.invokeSuspend(DeckPicker.java:468)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7720)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
Hii @david-allison! I'm planning to fix this by adding a guard clause in showDeckPickerContextMenu immediately after the viewModel.selectDeck(deckId).join() call.
If isFinishing || supportFragmentManager.isStateSaved is true, I will return early, log a Timber warning, and use CrashReportService.sendExceptionReport with onlyIfSilent = true to report the issue as requested. Does this approach look correct to you?
Firstly, here's the logcat, have a look to see if you can see the issue.
(I suspect there's nothing of use.)
--------- beginning of kernel
--------- beginning of main
04-08 18:05:32.348 I/AnkiDroid(21125): DeckPicker::onStart
04-08 18:05:32.356 I/AnkiDroid(21125): DeckPicker::oa::onStart
04-08 18:05:32.395 I/AnkiDroid(21125): DeckPicker::onResume
04-08 18:05:32.424 I/AnkiDroid(21125): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
04-08 18:05:32.424 I/AnkiDroid(21125): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
04-08 18:05:32.424 I/AnkiDroid(21125): scoped internal dir: /data/user/0/com.ichi2.anki/files
04-08 18:05:32.424 I/AnkiDroid(21125): isLegacyStorage(): false
04-08 18:05:32.439 I/AnkiDroid(21125): DeckPicker::oa::onResume
04-08 18:05:32.565 I/AnkiDroid(21125): configureToolbarInternal()
04-08 18:05:35.319 W/AnkiDroid(21125): m3/ blocked main thread for 2733ms:
04-08 18:05:35.319 W/AnkiDroid(21125): g9.m3.j(r8-map-id-01f5a25340c7062dc4ec5de3e5f37ac689558841a578e0ff0d7d71e0dbda22c0:61)
04-08 18:05:40.404 W/AnkiDroid(21125): m3/ blocked main thread for 5046ms:
04-08 18:05:40.404 W/AnkiDroid(21125): g9.m3.j(r8-map-id-01f5a25340c7062dc4ec5de3e5f37ac689558841a578e0ff0d7d71e0dbda22c0:61)
04-08 18:05:41.702 I/AnkiDroid(21125): Displaying progress dialog: 600ms elapsed;
04-08 18:05:41.702 I/AnkiDroid(21125): cancellable: false;
04-08 18:05:41.702 I/AnkiDroid(21125): manualCancel: false
04-08 18:05:41.702 I/AnkiDroid(21125):
04-08 18:05:42.166 I/AnkiDroid(21125): configureToolbarInternal()
04-08 18:05:42.790 I/AnkiDroid(21125): configureToolbarInternal()
04-08 18:05:48.490 I/AnkiDroid(21125): DeckPicker::onPause
04-08 18:05:48.505 I/AnkiDroid(21125): DeckPicker::oa::onPause
04-08 18:05:48.571 I/AnkiDroid(21125): DeckPicker::onStop
04-08 18:05:48.633 I/AnkiDroid(21125): DeckPicker::oa::onStop
04-08 18:05:48.707 I/AnkiDroid(21125): DeckPicker::onSaveInstanceState
04-08 18:05:48.717 I/AnkiDroid(21125): DeckPicker::oa::onSaveInstanceState
04-08 18:05:51.523 I/AnkiDroid(21125): DeckPicker::onStart
04-08 18:05:51.535 I/AnkiDroid(21125): DeckPicker::oa::onStart
04-08 18:05:51.592 I/AnkiDroid(21125): DeckPicker::onResume
04-08 18:05:51.693 I/AnkiDroid(21125): isLegacyStorage(): current dir: /storage/emulated/0/Android/data/com.ichi2.anki/files/AnkiDroid1
04-08 18:05:51.693 I/AnkiDroid(21125): scoped external dirs: /storage/emulated/0/Android/data/com.ichi2.anki/files
04-08 18:05:51.693 I/AnkiDroid(21125): scoped internal dir: /data/user/0/com.ichi2.anki/files
04-08 18:05:51.694 I/AnkiDroid(21125): isLegacyStorage(): false
04-08 18:05:53.614 W/AnkiDroid(21125): m3/ blocked main thread for 1865ms:
04-08 18:05:53.614 W/AnkiDroid(21125): g9.m3.j(r8-map-id-01f5a25340c7062dc4ec5de3e5f37ac689558841a578e0ff0d7d71e0dbda22c0:61)
04-08 18:05:53.614 I/AnkiDroid(21125): DeckPicker::oa::onResume
04-08 18:05:53.652 I/AnkiDroid(21125): configureToolbarInternal()
04-08 18:05:55.611 W/AnkiDroid(21125): m3/ blocked main thread for 1954ms:
04-08 18:05:55.611 W/AnkiDroid(21125): g9.m3.j(r8-map-id-01f5a25340c7062dc4ec5de3e5f37ac689558841a578e0ff0d7d71e0dbda22c0:61)
04-08 18:05:56.178 I/AnkiDroid(21125): Displaying progress dialog: 600ms elapsed;
04-08 18:05:56.178 I/AnkiDroid(21125): cancellable: false;
04-08 18:05:56.178 I/AnkiDroid(21125): manualCancel: false
04-08 18:05:56.178 I/AnkiDroid(21125):
04-08 18:05:56.788 W/AnkiDroid(21125): m3/ blocked main thread for 473ms:
04-08 18:05:56.788 W/AnkiDroid(21125): g9.m3.j(r8-map-id-01f5a25340c7062dc4ec5de3e5f37ac689558841a578e0ff0d7d71e0dbda22c0:61)
04-08 18:05:56.842 I/AnkiDroid(21125): configureToolbarInternal()
04-08 18:05:57.422 I/AnkiDroid(21125): configureToolbarInternal()
04-08 18:05:58.039 W/AnkiDroid(21125): m3/ blocked main thread for 616ms:
04-08 18:05:58.039 W/AnkiDroid(21125): g9.m3.j(r8-map-id-01f5a25340c7062dc4ec5de3e5f37ac689558841a578e0ff0d7d71e0dbda22c0:61)
- No need for the ACRA report in this case.
- I don't see why
isFinishing || supportFragmentManager.isStateSavedis used - this is a general issue for showing the context menu dialog when the activity is stopped (possibly if the operation is queued after syncing), it should be sufficient to use a safeshowDialogFragmentcall, which catches and logs the exception
No need for the ACRA report in this case. I don't see why isFinishing || supportFragmentManager.isStateSaved is used - this is a general issue for showing the context menu dialog when the activity is stopped (possibly if the operation is queued after syncing), it should be sufficient to use a safe showDialogFragment call, which catches and logs the exception
Got it, @david-allison . I'll implement the safe showDialogFragment call. I noticed that showDeckPickerRightClickContextMenu could face the same issue. Should I apply the same safe logic (try-catch block) there as well? What do you think?
I'd need to see the PR for that one.
[2.25] The best fix would be to move the functionality into the DeckPicker ViewModel and test it, as that's where we want to be long-term architecturally.
[2.24.1] Short-term: a safe method, used for known buggy cases [due to syncing] would be acceptable, DeckPicker only
I'd go for the 2.25 approach now time has passed and we're released, we want to release 2.25 quickly to fix a few complaints with the tablet mode editor/previewer split screen, and a quick hack to fix an uncommon bug would be wasted resources