Skip to content

Fix file reopening after exit confirmation on Android#45

Merged
adeeteya merged 2 commits intomasterfrom
copilot/fix-file-reopening-issue
Nov 11, 2025
Merged

Fix file reopening after exit confirmation on Android#45
adeeteya merged 2 commits intomasterfrom
copilot/fix-file-reopening-issue

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you added the feature to the features column of readme.md ? (N/A - bug fix)

Description

Fixes #40 - Files opened via Android Intent persist in MainActivity memory after exit confirmation, causing them to reopen when launching from recent apps.

Root cause: launchMode="singleTop" prevents Activity destruction on exit. fileContentToSend remains populated and gets sent again on app restore.

Changes:

  • Android (MainActivity.kt): Added clearFileContent method channel handler to null out stored file content
  • Flutter (home.dart): Call clearFileContent before SystemNavigator.pop() in exit confirmation handler
// MainActivity.kt
when (call.method) {
    "getFileContent" -> {
        result.success(fileContentToSend)
        fileContentToSend = null
    }
    "clearFileContent" -> {
        fileContentToSend = null  // Clear on explicit exit
        result.success(null)
    }
    else -> result.notImplemented()
}
// home.dart
final bool shouldPop = await _showExitConfirmationDialog();
if (shouldPop && context.mounted) {
    await _clearFileContent();  // Clear before exit
    await SystemNavigator.pop(animated: true);
}

Result: Clean app state on restore, no stale file content.

Original prompt

This section details on the original issue you should resolve

<issue_title>after closing a file (resp. the app and confirming) the file get's reopened by itself</issue_title>
<issue_description>Describe the bug
i found a somewhat odd behavior... so this is more or less a follow up on #18:
at least on Android since version 2.0.0 Markdown Editor asks every time you want to exit it via back button - also if you haven't changed anything or even if there is nothing in the input field - for confirmation... which is IMHO unnecessary for these 2 cases, but ok.
the issue is, after confirming - and hence agreeing to close the file and lose all (unsaved) edits, exact the same file opens again if you open Markdown-Editor from the history.

to rule out a possible misunderstanding: i'm not talking about the situation when the app was just put in the background via home button or the like! - in this situation it doesn't asks for confirmation and keeps the edits, which is fine and expected. 👍

To Reproduce
Steps to reproduce the behavior:

  1. open a file via file browser in Markdown Editor
    (interestingly if i open Markdown Editor first and the file via its menu, is seems to work more or less as expected as also an empty Markdown Editor gets opened afterwards via the app history.)
  2. make some - minor - edits (perhaps at the end or somewhere in-between of a long file)
  3. notice before saving that some of the edits were wrong and you would rather restart your edits to be sure that nothing wrong gets saved... hence exit Markdown Editor (without saving) via back button and confirming it.
  4. notice that Markdown Editor is still in the app history and to spare some time use that to open the app.
  5. be surprised that without adding anything, the file is also again/still(?) open.
  6. be unsure, if the edits - you don't want to keep - are still there or not... 😒

Expected behavior
after confirming to exit, i would expect at least the file to be really closed... as i don't want to be greeted with a file where i can't be sure if it still contains - potentially unsaved but discarded - edits, which i have to check first.
perhaps even better would be to really exit/end the app and don't show it in the history as some other apps with a explicit exit button behave (eg. Firefox), as this could also be a privacy issue in some circumstances as you can still see the previously opened file in the history (even after you confirmed to exit the app).

Smartphone (please complete the following information):

  • Device: Sony Xperia XA2
  • OS: Android 15 resp. LineageOS 22.2
  • Version 2.0.0 (8)
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: adeeteya <62930521+adeeteya@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bug causing file to reopen after closing Fix file reopening after exit confirmation on Android Nov 11, 2025
Copilot AI requested a review from adeeteya November 11, 2025 02:53
@adeeteya adeeteya marked this pull request as ready for review November 11, 2025 06:58
@adeeteya adeeteya merged commit 6ed5910 into master Nov 11, 2025
2 checks passed
@adeeteya adeeteya deleted the copilot/fix-file-reopening-issue branch November 11, 2025 06:58
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.

after closing a file (resp. the app and confirming) the file get's reopened by itself Can't open files on Windows

2 participants