From 8ec499ae3f0b2f265fce69b23d761fb61dfb38f8 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Wed, 25 Nov 2026 17:34:53 -0500 Subject: [PATCH] fix(session): relaunch into a fresh activity so Switch to Desktop does not leave the loader up (#3227) --- .../com/droiddeck/launcher/SessionActivity.kt | 16 ++++++++++++---- .../droiddeck/launcher/SessionRelaunchTest.kt | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/SessionRelaunchTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 122b17fc3b..f7468607dd 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -3414,8 +3414,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde if (status == 0) SessionState.takeRelaunch()?.let { next -> next.putExtra(EXTRA_RETURN_HOME, intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) next.putExtra(EXTRA_LINK_TASK, intent.getIntExtra(EXTRA_LINK_TASK, -1)) - setIntent(next) - recreate() + relaunch(next) return@runOnUiThread } showEnded(status, hint) @@ -3423,6 +3422,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde }, "session-end-hint").start() } + // recreate() keeps this window, and Compose content added to it afterwards never recomposes, so the + // loading screen of the next session stays up over a running session. A new instance gets its own window. + // This instance finishes first because the activity is singleTask and would otherwise take the intent itself. + private fun relaunch(next: Intent) { + closeAtOnce = true + super.finish() + startActivity(next) + overridePendingTransition(0, 0) + } + private fun showEnded(status: Int, hint: EndHint?) { if (status == 0 && hint?.evenOnSuccess != true) { finish() @@ -6050,8 +6059,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde Log.w(TAG, "ignoring agent start while session phase is ${SessionState.phase}") return } - setIntent(intent) - recreate() + relaunch(android.content.Intent(intent).setClass(this, SessionActivity::class.java)) return } if (this.intent.getBooleanExtra(EXTRA_RETURN_HOME, false)) intent.putExtra(EXTRA_RETURN_HOME, true) diff --git a/app/src/test/java/com/droiddeck/launcher/SessionRelaunchTest.kt b/app/src/test/java/com/droiddeck/launcher/SessionRelaunchTest.kt new file mode 100644 index 0000000000..8424dcedfa --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/SessionRelaunchTest.kt @@ -0,0 +1,18 @@ +package com.droiddeck.launcher + +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +class SessionRelaunchTest { + // recreate() keeps the window, and Compose content set on it afterwards never recomposes (#2668): + // a session relaunched that way kept its loading screen up over a running desktop. + @Test fun sessionAndLauncherActivitiesNeverRecreateThemselves() { + listOf("SessionActivity.kt", "FrontEndActivity.kt").forEach { name -> + val code = File("src/main/java/com/droiddeck/launcher/$name").readLines() + .map { it.substringBefore("//") } + val calls = code.withIndex().filter { (_, line) -> Regex("""\brecreate\(\)""").containsMatchIn(line) } + assertTrue("$name calls recreate() at line(s) ${calls.map { it.index + 1 }}", calls.isEmpty()) + } + } +}