Fix back button navigation for documents opened within app
Fixes #392 - App now returns to main screen instead of closing when pressing back after opening documents through internal file chooser.
Problem
When users opened documents via the app's file chooser or recent documents, pressing the back button would close the entire app instead of returning to the main screen. This was unexpected UX behavior that differed from typical Android navigation patterns.
The correct behavior should be:
- Internal navigation (file chooser/recent docs): Back button â return to main screen
- External launch (opened from file manager/email): Back button â close app
Solution
Added tracking of document source and custom back button handling to provide appropriate navigation based on how the document was opened.
Key Changes
-
Track document source: Added
documentOpenedInternallyboolean flag -
Internal navigation: Set flag to
truefor file chooser and recent documents -
External navigation: Set flag to
falsefor app launches with intent data -
Custom back handling: Use modern
OnBackPressedCallbackwith conditional logic -
Return navigation: Added
showLandingScreen()method to navigate back to main screen
Navigation Behavior After Fix
- â File chooser â document â BACK â main screen (was: close app)
- â Recent documents â document â BACK â main screen (was: close app)
- â External app â document â BACK â close app (unchanged)
- â Fullscreen mode â BACK â exit fullscreen (unchanged)
Files Modified
-
MainActivity.java: Added source tracking and back button handling (~35 lines) -
RecentDocumentDialogFragment.java: Use internal navigation method (1 line)
The implementation is minimal and surgical, preserving all existing functionality while solving the UX issue described in the original problem statement.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.google.com
- Triggering command:
/usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx1536M -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.9-bin/90cnw93cvbtalezasaz0blq0a/gradle-8.9/lib/gradle-daemon-main-8.9.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.9-bin/90cnw93cvbtalezasaz0blq0a/gradle-8.9/lib/agents/gradle-instrumentation-agent-8.9.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.9(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
ð¡ You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.