Repository navigation
#1328 Deliver the restore file picker result on Android 10 - #1822
Open
numericOverflow wants to merge 2 commits into
Open
numericOverflow wants to merge 2 commits into
numericOverflow wants to merge 2 commits into
Conversation
MainActivity was singleInstance, so the system started the document pickers in a new task. On older Android versions that cancels the activity result at once, and the restore callback ignored the cancel, so picking a backup did nothing. singleTask keeps one MainActivity instance but lets the picker run in the app's task, so its result is delivered. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
Futsch1
requested changes
Oct 24, 2026
Owner
|
Still draft? |
Review feedback on Futsch1#1822: the test adds no value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
numericOverflow
marked this pull request as ready for review
October 27, 2026 14:46
Futsch1
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


I was trying to generate some test data & restore on a spare phone, but hit this bug where restore doesn't work.
I also noticed that I had 2 "windows" in the launcher history: one for main app, and one for file picker. this fix got rid of that and now I have just a single window even after picking files.
</humanGenerated>
Now for the AI generated part...
Restore backup does nothing after picking the file (Android 10)
Related upstream issue: #1328 ("Restore of backup not possible").
Summary
On Android 10, Restore > OK opens the system file picker, the user picks a backup made by the app, the picker closes, and nothing happens: no progress dialog, no "Restore successful" or "Restore failed" dialog, no crash. The cause is that
MainActivityuseslaunchMode="singleInstance", so the system starts the picker in a separate task and cancels the result at once. The fix changes the launch mode tosingleTask.Steps to reproduce
Expected vs actual
Environment
main), FOSS debug build.Cause
MainActivityis declared withandroid:launchMode="singleInstance"(app/src/main/AndroidManifest.xml:47). It was added in v1.5.0 with the theme-switch fix.singleInstanceactivity must be the only activity in its task. So when it starts another activity, the system addsFLAG_ACTIVITY_NEW_TASKand puts the started activity in a new task. On older Android versions the system then cancels the pending activity result immediately ("Activity is launching as a new task, so cancelling activity result.").PickActivity) as its own entry in Recents, separate from MedTimer. After the pick, MainActivity comes back with the same activity record and process, and no new window (progress or result dialog) is added.AppOptionsActionsImpl.kt:49-56only acts onRESULT_OK. The earlyRESULT_CANCELEDis ignored without a log or a message, and the real result from the picker never reaches the app. So the user sees nothing.Fix
app/src/main/AndroidManifest.xml:47:android:launchMode="singleInstance"changed toandroid:launchMode="singleTask".singleTask,MainActivityis still the only instance and still the root of its task, but other activities can run in the same task. The picker now opens in MedTimer's task, so the system does not cancel the result andRESULT_OKwith the file Uri reaches the callback.app/src/test/java/com/futsch1/medtimer/MainActivityLaunchModeTest.kt(Robolectric) asserts that the merged manifest declaresMainActivityassingleTask, with a comment that names Restore of backup not possible #1328.Side effects of the fix
MainActivity(for example a notification tap) while the picker or the intro is open, the system closes the screens aboveMainActivity. Tapping the launcher icon returns to the task with the picker still on top.MainActivityinstance.onNewIntenthandling is unchanged. The theme switch (finish, then restart) uses the same path as before.ReminderAlarmActivitykeeps its ownsingleInstancemode and is not affected.How Fix was verified
:app:testFullDebugUnitTest,:app:testFossDebugUnitTest(including the new guard test),:app:lintFullDebug,:app:lintFossDebugand:app:assembleFossDebugpass.Possibly related, not confirmed
The automatic-backup folder picker (
ACTION_OPEN_DOCUMENT_TREE,BackupManager.kt:352, callbackAppOptionsActionsImpl.kt:58-62) uses the same result path from the same activity, so on older Android its result may also be cancelled and no folder saved (compare the late comment in #1519). The same change would fix it.Generated with Claude Code