Repository navigation
Fix blank puzzle screen after the app is recreated - #13
Merged
atorch merged 4 commits intoNov 14, 2026
Merged
Conversation
When Android recreates SolvePuzzle, onCreate's savedInstanceState != null branch never calls setContentView, so the user gets an empty screen under the action bar. This happens after the app is killed in the background, or after a setting change the manifest doesn't list in configChanges (dark mode, font size, language, split-screen resizing). Robolectric tests, run on the JVM as part of ./gradlew build, cover both cases: a configuration change, and process death (a brand new activity built from the saved state alone). Each test enters one correct country, recreates the activity, and checks that the same puzzle and progress are shown and that the next correct country is still accepted. Both tests fail at this commit. The fix follows in the next commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HwXCddsMirbBTNqxSqT6iv
CI only keeps the build log, and Gradle's default test output there is one line per failure, which isn't enough to diagnose anything. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HwXCddsMirbBTNqxSqT6iv
Both tests failed before running any test code. Robolectric's FileDescriptorInterceptor (used by ApplicationSharedMemory.create while setting up the Android 16 environment) calls jdk.internal.access.SharedSecrets through reflection, which JDK 17+ refuses unless that package is exported. Export it, and open java.io for the interceptor's fallback path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HwXCddsMirbBTNqxSqT6iv
onCreate now always calls setContentView. It used to skip it when savedInstanceState != null, leaving a blank screen. - The puzzle state moves from static fields to instance fields. Statics don't survive the app being killed in the background, and the static TextView/ImageView fields leaked the activity. - onSaveInstanceState saves the start and destination indices and the countries entered so far. - On restore, onCreate reloads that puzzle's paths and replays the entered countries (moveTo), without repeating the toasts or database updates. A solved puzzle comes back solved. - The answer check uses equals() instead of ==. Strings restored from a Bundle are new objects, so == would reject correct answers. - path_length_inner comes from the stored path itself. Every puzzle in graph_paths_summary.csv has paths in graph_paths_subset.csv whose length matches, so this doesn't change new puzzles. Makes SolvePuzzleRecreationTest pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HwXCddsMirbBTNqxSqT6iv
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues blocking approval of the puzzle-state restoration changes.
No open issues 🎉
What changed in this PR
Fixes the blank puzzle screen after Android recreates SolvePuzzle, preserving the selected puzzle and progress. This PR builds on #11’s modernized build setup.
Changes:
- Moves puzzle state to instance fields and restores the screen by replaying saved progress without repeating toasts or database writes.
- Adds regression tests for configuration-change and process-death restoration.
- Configures Robolectric dependencies, JVM access flags, and full failure logging.
| File | Description |
|---|---|
gradle/libs.versions.toml |
Adds JUnit and Robolectric dependency definitions. |
app/src/test/java/atorch/shortestpaths/SolvePuzzleRecreationTest.java |
Tests puzzle restoration and continued solving after recreation. |
app/src/main/java/atorch/shortestpaths/SolvePuzzle.java |
Rebuilds the screen, saves and restores progress, and compares answers by value. |
app/build.gradle |
Enables resource-aware unit tests and configures Robolectric execution and logging. |
Review effort: Balanced
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.
Stacked on #11. The new tests need #11's build setup: Robolectric for SDK 36 runs on JDK 21, and
mainstill builds on JDK 11. Once #11 merges, change this PR's base tomain.The bug
When Android recreates
SolvePuzzle,onCreatetakes thesavedInstanceState != nullbranch (// TODO This is most likely wrong). That branch never callssetContentView, so the user gets an empty screen under the action bar. It doesn't crash, so it never shows up in Android vitals.Recreation happens:
configChanges: dark mode, font size, language, resizing in split-screen.Manual repro against the current Play version: open a puzzle, then toggle dark mode. Or turn on Developer options → "Don't keep activities", open a puzzle, press Home, and come back.
Tests
SolvePuzzleRecreationTestuses Robolectric. It runs on the JVM as part of./gradlew build, so CI needs no emulator. Each test:Commits, and what CI showed for each
jdk.internal.access, which JDK 21 blocks.--add-exports/--add-openson the test task). CI failed for the right reason, in both tests:AssertionError: After recreation the puzzle screen is blank: there's no answer field.Fix
staticfields to instance fields. Statics are lost when the app is killed, and the staticTextView/ImageViewfields also leaked the activity.onSaveInstanceStatesaves the start and destination indices and the countries entered so far.onCreatealways builds the screen. When restoring, it reloads that puzzle's paths and replays the entered countries, without repeating the toasts or database writes. A solved puzzle comes back solved.equals()instead of==. Strings restored from aBundleare new objects, so==would reject correct answers after a restore.Not yet done
Note for #10
#10 adds a
static ArrayList<String> user_routetoSolvePuzzle. This PR adds the same thing as an instance field with the same name. When #10 is rebased, itsuser_route.add(...)/clear()lines can simply be dropped.🤖 Generated with Claude Code
https://claude.ai/code/session_01HwXCddsMirbBTNqxSqT6iv