Retain AchievementManager UI notifier instead of weakly referencing it#78
Closed
Copilot wants to merge 2 commits into
Closed
Retain AchievementManager UI notifier instead of weakly referencing it#78Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Fix code as per review comment 3380005450
Retain AchievementManager UI notifier instead of weakly referencing it
Jun 9, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes an unintended notifier lifecycle issue in AchievementManager where UI callbacks could disappear due to storing the UiNotifier in a WeakReference. It updates the manager to retain the notifier strongly until it is explicitly cleared, which better matches the expected callback lifecycle (including the Android toast-backed notifier path).
Changes:
- Replace
WeakReference<UiNotifier?>storage with a strongUiNotifier?field. - Update
setCurrentActivity()to install/clear the toast-backed notifier via strong assignment (setsnullwhen activity is cleared). - Add an Android instrumentation regression test verifying the notifier instance is retained and then cleared.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/src/main/java/roboyard/logic/achievements/AchievementManager.kt | Switch notifier storage to a strong reference; adjust Android activity adapter setup and update-nudge dispatch accordingly. |
| app/src/androidTest/java/roboyard/eclabs/achievements/AchievementManagerTest.java | Add regression test asserting setUiNotifier() retains the exact instance and clears it when set to null. |
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.
The reviewed code stored
AchievementManager'sUiNotifierin aWeakReference, which allowed notifier callbacks to disappear unexpectedly. This change keeps the notifier alive until it is explicitly cleared, matching the intended callback lifecycle.Notifier lifetime
WeakReference<UiNotifier?>with a strongUiNotifier?setUiNotifier()to store the notifier directly and clear it onnullAndroid adapter path
setCurrentActivity()to install the toast-backed notifier as a strong referenceRegression coverage
setUiNotifier(notifier)setUiNotifier(null)