Skip to content

Do not show the unsaved-edits dialog on a closing activity - #735

Merged
andiwand merged 1 commit into
mainfrom
fix/722-leaving-edits-dialog
Oct 25, 2026
Merged

andiwand merged 1 commit into
mainfrom
fix/722-leaving-edits-dialog

Conversation

@andiwand

@andiwand andiwand commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Fixes #722.

MainActivity.onDestroy finishes the edit action mode. EditActionModeCallback.onDestroyActionMode then calls confirmLeavingEdits if the document has unsaved edits, so the activity shows an AlertDialog on a window that is going away. Android throws BadTokenException, or logs WindowLeaked.

The most common path: a user leaves a document that another app opened, and taps "Discard". leaveApp finishes the activity, but the edits are still in the page, so the destroy asks again. A finish or a recreate with unsaved edits in edit mode has the same result.

Changes

  • confirmLeavingEdits returns when the activity is finishing or destroyed. The edits go with the activity, as before.

Testing

  • spotlessCheck assembleProDebug assembleLiteDebug testProDebugUnitTest pass (against core 7.6.0 locally, because 7.6.1 is not on Maven Central yet).
  • On the emulator (Android 12), a device test filled a sheet cell in edit mode and finished the activity. Without the fix, the log shows show_alert_unsaved_changes and WindowLeaked. With the fix, it shows neither. This emulator does not throw BadTokenException, so the test cannot fail here, and I did not add it.

@andiwand
andiwand force-pushed the fix/722-leaving-edits-dialog branch from 67746a3 to 1d5df3a Compare October 25, 2026 13:05
Base automatically changed from core-7.6.0 to main October 25, 2026 13:19
@andiwand
andiwand force-pushed the fix/722-leaving-edits-dialog branch from 1d5df3a to cd1ae27 Compare October 25, 2026 13:22
onDestroy finishes the edit action mode. The mode then asks about
unsaved edits, so MainActivity shows an AlertDialog on a window that
is going away. Android throws BadTokenException, or logs WindowLeaked.

The most common path: a user leaves a document that another app
opened, and discards the edits. leaveApp finishes the activity, but
the edits are still in the page, so the destroy asks again.

confirmLeavingEdits now returns when the activity is finishing or
destroyed.

Fixes #722

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JuNa2W75khbpynkiG9iDqF
@andiwand
andiwand force-pushed the fix/722-leaving-edits-dialog branch from cd1ae27 to 1b511ba Compare October 25, 2026 13:27
@andiwand
andiwand merged commit f4b1802 into main Oct 25, 2026
2 of 3 checks passed
@andiwand
andiwand deleted the fix/722-leaving-edits-dialog branch October 25, 2026 13:29
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.

BadTokenException in MainActivity.confirmLeavingEdits

1 participant