Skip to content

#1328 Deliver the restore file picker result on Android 10 - #1822

Open
numericOverflow wants to merge 2 commits into
Futsch1:mainfrom
numericOverflow:1328-restore-picker-result
Open

numericOverflow wants to merge 2 commits into
Futsch1:mainfrom
numericOverflow:1328-restore-picker-result

Conversation

@numericOverflow

@numericOverflow numericOverflow commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

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...

This change was made with Claude Code (AI-assisted). I reviewed it and tested it on an Android 10 device.

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 MainActivity uses launchMode="singleInstance", so the system starts the picker in a separate task and cancels the result at once. The fix changes the launch mode to singleTask.

Steps to reproduce

  1. Create a backup with options menu > Backup and save the file on the device.
  2. Open options menu > Restore and tap OK.
  3. In the file picker, pick the backup file.

Expected vs actual

  • Expected: the progress dialog shows, then "Restore successful", and the data is restored.
  • Actual: the picker closes and the app shows nothing. The data does not change.

Environment

  • MedTimer 1.26.1 code base (current main), FOSS debug build.
  • Android 10 (API 29).
  • The same symptom is reported in Restore of backup not possible #1328 on Android 9. A commenter there reports that Android 15 works.

Cause

  • MainActivity is declared with android:launchMode="singleInstance" (app/src/main/AndroidManifest.xml:47). It was added in v1.5.0 with the theme-switch fix.
  • A singleInstance activity must be the only activity in its task. So when it starts another activity, the system adds FLAG_ACTIVITY_NEW_TASK and 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.").
  • On the test device the log shows the DocumentsUI picker (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.
  • The callback in AppOptionsActionsImpl.kt:49-56 only acts on RESULT_OK. The early RESULT_CANCELED is 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 to android:launchMode="singleTask".
  • With singleTask, MainActivity is 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 and RESULT_OK with the file Uri reaches the callback.
  • New guard test app/src/test/java/com/futsch1/medtimer/MainActivityLaunchModeTest.kt (Robolectric) asserts that the merged manifest declares MainActivity as singleTask, with a comment that names Restore of backup not possible #1328.

Side effects of the fix

  • Recents shows one MedTimer card. The file picker and the app intro screen now open inside MedTimer's task instead of in their own cards. Back from them returns to the main screen.
  • If the app is brought to the front by an intent to MainActivity (for example a notification tap) while the picker or the intro is open, the system closes the screens above MainActivity. Tapping the launcher icon returns to the task with the picker still on top.
  • Still only one MainActivity instance. onNewIntent handling is unchanged. The theme switch (finish, then restart) uses the same path as before.
  • ReminderAlarmActivity keeps its own singleInstance mode and is not affected.

How Fix was verified

  • Root cause: device logs on the Android 10 phone before the fix (picker in a separate task, no dialog after the pick, no crash, no activity recreation).
  • :app:testFullDebugUnitTest, :app:testFossDebugUnitTest (including the new guard test), :app:lintFullDebug, :app:lintFossDebug and :app:assembleFossDebug pass.
  • Android 10 device, restore a backup made by the app and expect "Restore successful"; check theme switch, a reminder notification tap, and the alarm screen.
  • Automatic Backup location prompted once, then worked properly to write a backup to location selected & did not prompt for location again.

Possibly related, not confirmed

The automatic-backup folder picker (ACTION_OPEN_DOCUMENT_TREE, BackupManager.kt:352, callback AppOptionsActionsImpl.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

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>
@numericOverflow

numericOverflow commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Pics for proof

Screenshot_20261023-105422_MedTimer Screenshot_20261023-105350_MedTimer

Comment thread app/src/test/java/com/futsch1/medtimer/MainActivityLaunchModeTest.kt Outdated
@Futsch1

Futsch1 commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Still draft?

Review feedback on Futsch1#1822: the test adds no value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@numericOverflow
numericOverflow marked this pull request as ready for review October 27, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants