Skip to content

Keep a view ID resolving after a background and foreground cycle - #603

Draft
arifBurakDemiray wants to merge 1 commit into
stagingfrom
board/view-id-lost-after-background-foreground-android
Draft

arifBurakDemiray wants to merge 1 commit into
stagingfrom
board/view-id-lost-after-background-foreground-android

Conversation

@arifBurakDemiray

Copy link
Copy Markdown
Member

Board card C-2: A view ID stops working after a background and foreground cycle

Primary source: the swift-sdk-review-2026-09-24 code-review sweep. The card names countly-sdk-swift's ViewsModule (restartedViewIDs, currentID(for:)) as the reference implementation.

What breaks without this

ModuleViews.startStoppedViews reopens every view that was closed on background under a new view ID and drops the old viewDataMap entry. A host that saved the ID returned by startView and later calls stopViewWithID with it hits an unknown ID once the app has been backgrounded:

  • the call is ignored with there is no view with the provided view id to close,
  • the reopened view is never closed, so it reports a fresh visit and a duration on every later foreground while the user is on other screens.

The same applies to pauseViewWithID, resumeViewWithID and addSegmentationToViewWithID.

Nothing on the wire changes. Only the ID the host holds has to keep resolving.

What changed

sdk/src/main/java/ly/count/android/sdk/ModuleViews.java:

  • New restartedViewIDs map from each handed-out view ID to the ID its view is open under now.
  • currentIDFor(String) resolves a host-held ID, returning the input unchanged when the view was never restarted.
  • rememberRestartedView(old, new) repoints existing entries that pointed at the old ID and adds old -> new, so an ID survives repeated background cycles.
  • forgetRestartedView(id) drops every entry keyed by or pointing at an ID when the view is finally stopped. Called from stopViewWithIDInternal (the !willStartAgain branch), from autoCloseRequiredViews when it closes all views, and from startStoppedViews when a view could not be reopened.
  • stopViewWithIDInternal, pauseViewWithIDInternal, resumeViewWithIDInternal and addSegmentationToViewWithIDInternal resolve through currentIDFor after their null check. Internal callers pass an already-current ID, which currentIDFor returns unchanged.

sdk/src/androidTest/.../ModuleViewsTests.java: regression test startView_viewIDResolvesAfterBackgroundForeground asserting the saved ID still closes the view after an onStop/onStart cycle and that nothing is left behind.

CHANGELOG.md: one entry under the unreleased ## XX.XX.XX heading.

No public API change, no minimum version change.

What I did not verify

  • The instrumented tests were not run. ModuleViewsTests lives in androidTest and needs a device or emulator; none was attached on the machine that produced this branch. The new test has never been executed.
  • Only compilation was checked: :sdk:compileDebugJavaWithJavac and :sdk:compileDebugAndroidTestJavaWithJavac both pass on JDK 17.
  • No manual run against a real app or server, so the end-to-end event stream after a background cycle is unconfirmed.
  • The countly-sdk-swift implementation was not read; the behaviour here follows the card's description of it, not the Swift source.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Dependency security scan

Scanned 515 resolved dependencies — 289 buildscript, 14 published, 212 sample.

Findings Count
Blocking (HIGH+ in published/sample) 0
Below HIGH, in dependencies we control 1
Waived via allowlist 2
Build tooling — not upgradeable from this repo 88
Below the HIGH threshold, but ours to upgrade (1)
Severity Dependency Advisory Fixed in Used by
MODERATE com.google.android.gms:play-services-basement:18.0.0 GHSA-cm6r-892j-jv2g — Google Play Services SDK leads to apps having incorrectly set mutability flag 18.0.2 :app
Waived via allowlist (2)
Advisory Dependency Expires Reason
GHSA-r937-wjx7-w2jp org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.10 2026-11-30 Kotlin Gradle plugin build-cache deserialization. First fixed in 2.4.20-Beta1; no stable Kotlin release carries the fix yet. Build-machine only (CVSS AV:L/AC:H/PR:H), never shipped to integrators. Drop this entry once 2.4.20 is stable.
GHSA-r937-wjx7-w2jp org.jetbrains.kotlin:kotlin-gradle-plugin:2.4.10 2026-11-30 Kotlin Gradle plugin build-cache deserialization. First fixed in 2.4.20-Beta1; no stable Kotlin release carries the fix yet. Build-machine only (CVSS AV:L/AC:H/PR:H), never shipped to integrators. Drop this entry once 2.4.20 is stable.

88 further finding(s) in Gradle plugin internals are reported in the job summary and the resolved-dependencies artifact. They ship inside the build plugins and cannot be upgraded from this repository.

Result: passed

Full run log

@github-actions

Copy link
Copy Markdown

Unit Test Results 🚀

1 077 tests  +1   1 077 ✅ +1   7m 35s ⏱️ + 1m 55s
   66 suites ±0       0 💤 ±0 
    3 files   ±0       0 ❌ ±0 

Results for commit dfc29a7. ± Comparison against base commit cb163c6.

@arifBurakDemiray arifBurakDemiray changed the title [board] Keep a view ID resolving after a background and foreground cycle Keep a view ID resolving after a background and foreground cycle Sep 29, 2026

This branch has not been deployed

No deployments
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.

1 participant