From d6c400aca31fb2474e44696bc09f55ed7b473e82 Mon Sep 17 00:00:00 2001 From: Song Eric Yu Li Date: Wed, 27 Aug 2025 14:32:37 -0600 Subject: [PATCH] fix: stop duplicate permissions request screen When AnkiDroid requests mandatory permissions on first-time-launch -- particularly below API 29 when it requests the storage permission -- providing the permission and then hitting continue causes the window to appear a second time. The user then needs to hit "Continue" for a second time. Looking through the logs, this seems to be because the `onStartupResponse` listener attached to the StartupResponse StateFlow is being triggered twice with the RequestPermissions state, despite RequestPermissions only being posted to the StateFlow exactly once. This change sets the StateFlow's value to null when the RequestPermissions state is received, ensuring duplicate listener calls do not occur and ensuring the permission screen is only launched once. --- AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt index 7d8e8c2ee251..02f0d8d5fd72 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt @@ -814,10 +814,12 @@ open class DeckPicker : fun onStartupResponse(response: StartupResponse) { Timber.d("onStartupResponse: %s", response) when (response) { - is StartupResponse.RequestPermissions -> + is StartupResponse.RequestPermissions -> { + viewModel.flowOfStartupResponse.value = null // Prevent duplicate permission screen launches permissionScreenLauncher.launch( PermissionsActivity.getIntent(this, response.requiredPermissions), ) + } is StartupResponse.Success -> { showStartupScreensAndDialogs(sharedPrefs(), 0)