Stop reporting the app being switched away from as a failure
Backgrounding the app left "Lost the event stream (SocketTimeoutException: null)" waiting at the top on return. Android stops the activity, the socket dies with it, and the reconnect loop -- which kept running on a phone nobody was looking at -- recorded the failure. Switching apps is a choice somebody made, not a fault to report. Worse, it could not clear. `streamError` was reset when an event arrived, so a session that reconnected and then sat idle displayed a connection error it had already recovered from, indefinitely. That is the expensive half: a stale failure is indistinguishable from a live one. So the stream now runs only while the screen is at least STARTED, which makes the drop a deliberate close rather than an error (EventStream already distinguishes them), and resuming reconnects from the same cursor. What takes a failure off the screen is `onOpen` -- the measured moment the server accepted the connection -- rather than the first event to follow it. The message that does get shown leads with what will happen next rather than with the exception's class name, which named nothing the reader could act on. lifecycle-runtime-compose is declared rather than inherited from activity-compose, for the reason core-ktx already is: this code calls repeatOnLifecycle and LocalLifecycleOwner directly now, and a transitive could change under it. 2.11.0, the current stable. Verified on the emulator against an idle session, which is the case the old code could never clear: backgrounded 35s, returned, no banner -- and a message sent afterwards arrived live, so the reconnect genuinely reattached rather than merely staying quiet. Build, lint and ktfmt clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7c692a4ec
commit
aff2cb90e2
4 files changed
+71
-31
No files matched your search
@@ -13,6 +13,12 @@ androidx-activityCompose = "1.13.0"
|
||||
# .toUri), and a transitive it merely inherited could change under it.
|
||||
androidx-core-ktx = "1.19.0"
|
||||
zxing-embedded = "4.3.0"
|
||||
# Declared rather than inherited for the same reason as core-ktx: SessionScreen
|
||||
# now calls repeatOnLifecycle/LocalLifecycleOwner directly, to hold the event
|
||||
# stream open only while the screen is on screen. Latest stable, checked
|
||||
# 2026-08-29 against Google Maven; activity-compose alone would have pulled
|
||||
# 2.9.4.
|
||||
androidx-lifecycle = "2.11.0"
|
||||
# The Kotlin formatter, run at its defaults (see CODE_RULES rule 27). ktfmt
|
||||
# itself is Kotlin-org owned and has almost nothing to configure, which is
|
||||
# the point; this is the Gradle wrapper for it. Checked 2026-08-28.
|
||||
@@ -25,6 +31,7 @@ desugar-jdk-libs = "2.1.5"
|
||||
[libraries]
|
||||
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
|
||||
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core-ktx" }
|
||||
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
|
||||
# In-app QR scanner: a ready-made scanning Activity (camera preview, runtime
|
||||
# permission prompt, flashlight toggle) reached through the AndroidX Activity
|
||||
# Result API (ScanContract, added in 4.3.0). Fully offline -- no Play
|
||||
|
||||
Reference in new issue
Block a user