Skip to content

Fix blank puzzle screen after the app is recreated - #13

Merged
atorch merged 4 commits into
issue-7-modernize-sdk-and-depsfrom
fix-blank-puzzle-after-recreation
Nov 14, 2026
Merged

atorch merged 4 commits into
issue-7-modernize-sdk-and-depsfrom
fix-blank-puzzle-after-recreation

Conversation

@atorch

@atorch atorch commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #11. The new tests need #11's build setup: Robolectric for SDK 36 runs on JDK 21, and main still builds on JDK 11. Once #11 merges, change this PR's base to main.

The bug

When Android recreates SolvePuzzle, onCreate takes the savedInstanceState != null branch (// TODO This is most likely wrong). That branch never calls setContentView, 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:

  • after the app is killed in the background and the user comes back;
  • after any setting change not listed in the manifest's 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

SolvePuzzleRecreationTest uses Robolectric. It runs on the JVM as part of ./gradlew build, so CI needs no emulator. Each test:

  1. starts a level 1 puzzle and enters one correct country;
  2. recreates the activity, either through a configuration change or process death (a brand new activity built only from the saved state);
  3. checks that the same puzzle and route are shown and that the next correct country on the path is still accepted.

Commits, and what CI showed for each

  1. Add a failing test. CI failed, but inside Robolectric's setup rather than on the bug.
  2. Print full stack traces for failing unit tests. CI keeps only the log, so this stays. The trace showed Robolectric's Android 16 setup reaching into jdk.internal.access, which JDK 21 blocks.
  3. Let Robolectric's Android 16 sandbox start on JDK 21 (--add-exports/--add-opens on 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.
  4. The fix. CI is green and both tests pass.

Fix

  • State: the puzzle state moves from static fields to instance fields. Statics are lost when the app is killed, and the static TextView/ImageView fields also leaked the activity.
  • Saved state: onSaveInstanceState saves the start and destination indices and the countries entered so far.
  • Restore: onCreate always 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.
  • Answer check: it now uses equals() instead of ==. Strings restored from a Bundle are new objects, so == would reject correct answers after a restore.

Not yet done

  • Device check: this hasn't been run on a device. On a Pixel, toggle dark mode mid-puzzle and use "Don't keep activities"; both should bring back the same puzzle with your progress.

Note for #10

#10 adds a static ArrayList<String> user_route to SolvePuzzle. This PR adds the same thing as an instance field with the same name. When #10 is rebased, its user_route.add(...)/clear() lines can simply be dropped.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HwXCddsMirbBTNqxSqT6iv

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
@atorch
atorch marked this pull request as ready for review November 14, 2026 04:09
@atorch
atorch requested a balanced review from Copilot November 14, 2026 04:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@atorch
atorch merged commit c290f62 into issue-7-modernize-sdk-and-deps Nov 14, 2026
2 checks passed
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.

3 participants