From d35e907ba9a3e6a6cb424496f3c1b5cda3f6308f Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:07:54 +0000 Subject: [PATCH 1/2] fix: remove app from recents if in an invalid state After manual testing, the app no longer appears in Recents. I suspect this fixes: "android backup in progress, please try again" `Process.killProcess()` is a hard kill. I suspect some Android internals keep a reference to the process (users are reporting AnkiDroid being broken in the task list when the backup toast shows) If the app is in an invalid state within Android, it is feasible that Application.onCreate() is skipped, perpetually causing the "android backup in progress, please try again" toast. `finishAndRemoveTask` should stop this from occurring. Fixes 19050 - seen on a Samsung A35 --- .../ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt b/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt index 94189cfaaefe..6f3810c21af1 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt @@ -73,7 +73,10 @@ object AppLoadedFromBackupWorkaround { Themes.setTheme(this) // Avoids a SuperNotCalledException activitySuperOnCreate(savedInstanceState) - finish() + // Process.killProcess is a hard kill. I suspect that some Android OSes leave has the app in + // an invalid state after this occurs (meaning Application.onCreate is not called). + // Before killProcess, gracefully kill the app, removing it from the recents list + finishAndRemoveTask() // If we don't kill the process, the backup is not "done" and reopening the app show the same message. Thread { From c7dfd3382f3cf36c1506a85f8b898177da32d505 Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Sat, 7 Mar 2026 11:31:46 +0000 Subject: [PATCH 2/2] docs: add logging TODO if Application is uninitialized --- .../com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt b/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt index 6f3810c21af1..8f5c205eeefd 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/workarounds/AppLoadedFromBackupWorkaround.kt @@ -48,6 +48,7 @@ object AppLoadedFromBackupWorkaround { if (AnkiDroidApp.isInitialized) { return false } + // TODO: Timber likely does not work on this path - maybe add a check in IntentHandler // #7630: Can be triggered with `adb shell bmgr restore com.ichi2.anki` after AnkiDroid settings are changed. // Application.onCreate() is not called if: