Why Kotlin Channels Are the Natural Solution for Preventing "Double Execution" of Events

In Android app development, handling "one-shot events"—such as screen navigation or displaying toasts—has traditionally been a tricky area. The issue of processes running a second time after a screen rotation (Activity recreation) is a common headache for developers.

However, once you understand the mechanics of Channel, you will see that it is the most natural and effective solution to this problem.

 

🤔 Channels Have No "Inventory": Retrieve It, and It’s Gone

The decisive difference between Channel and its counterparts like StateFlow (or LiveData) lies in how they treat data.

  • StateFlow (The Bulletin Board): Data is "held" as a state. Even after someone looks at the data, it remains there. Any new observer will see the same, most recent data immediately (this is called being "sticky").
  • Channel (The Pipe/Mailbox): Data is meant to "pass through." The moment the receiver (Consumer) calls receive or collect, that specific piece of data is removed (consumed) from the Channel.

This concept of "consumption" is the essence of a Channel. Just like taking a letter out of a physical mailbox leaves the box empty, an event that has been processed once does not linger in memory.

 

🤔 How It Prevents Unintended Re-execution During Screen Rotation

This "disappears upon retrieval" behavior is incredibly effective during the recreation of Activities or Fragments. Let's look at the specific flow:

  • Event Fired: The ViewModel executes channel.send("Error").
  • Consumption: The UI (Activity A) collects this and shows a Toast. At this exact moment, the Channel becomes empty.
  • Screen Rotation: Activity A is destroyed, and Activity B is newly created.
  • Re-subscription: The new Activity B begins to collect from the channel again.

If this were StateFlow, the last piece of data ("Error") would still be there, causing Activity B to receive it immediately and trigger a second Toast.

However, the Channel is empty. Activity B simply enters a state of waiting for new events. It is impossible for the past event to trigger a malfunction.

 

🤔 Implementation Tip: receiveAsFlow and Buffering

In actual production code, it is standard practice to not expose the raw Channel, but rather expose it as a Flow to the receiver.


// ViewModel
// Use a buffer to prevent dropping events if the collector isn't ready immediately
private val _events = Channel<Event>(Channel.BUFFERED)
val events = _events.receiveAsFlow() // Exposed as a Flow

// UI (Activity/Fragment)
lifecycleScope.launch {
    viewModel.events.collect { event ->
        // Processing the event here consumes it from the Channel
        handleEvent(event)
    }
}

Using Channel.BUFFERED here is highly recommended. This ensures that if an event fires while the UI is not ready (e.g., the app is in the background), the event is held temporarily in memory. As soon as the UI resumes and calls collect, the event is delivered and consumed safely.

 

🤔 Summary: Channel is the Best Practice for "Disposable" Events

The "Receive = Consume" behavior of a Channel is not a side effect; it is the core feature designed for managing tasks that should only happen once.

The rule of thumb is simple:

  • If you need to hold a state (like UI text or loading status), use StateFlow.
  • If you need to consume an event (like navigation or errors), use Channel.

By strictly following this distinction, you can achieve safe, clean event handling without relying on complex flags or workarounds.


Why are updates to Kotlin, Compose, and KSP such a hassle?

In Android development, you're constantly dealing with the same set of three: Kotlin, the Compose Compiler, and KSP.

They seem like a friendly group, but their update schedules are always completely different! You upgrade Kotlin, and the Compose Compiler isn't compatible. You change something, and KSP throws a build error because of an internal API change...

To better manage this "dependency triangle" situation, the main idea is to use Renovate's configuration to treat them as a single unit. The simple plan is: "Raise all Kotlin ecosystem dependencies at the same time!"

 

🧑🏻‍💻 Brief overview of the renovate.json file


{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "config:base",
    "group:all",
    ":dependencyDashboard",
    "schedule:daily"
  ],
  "baseBranches": ["main"],
  "commitMessageExtra": "{{{currentValue}}} to {{#if isPinDigest}}{{{newDigestShort}}}{{else}}{{#if isMajor}}{{prettyNewMajor}}{{else}}{{#if isSingleVersion}}{{prettyNewVersion}}{{else}}{{#if newValue}}{{{newValue}}}{{else}}{{{newDigestShort}}}{{/if}}{{/if}}{{/if}}{{/if}}",
  "packageRules": [
    {
      "matchPackagePatterns": ["androidx.compose.compiler:compiler"],
      "groupName": "kotlin"
    },
    {
      "matchPackagePatterns": ["org.jetbrains.kotlin.*"],
      "groupName": "kotlin"
    },
    {
      "matchPackagePatterns": ["com.google.devtools.ksp"],
      "groupName": "kotlin"
    }
  ]
}

👉 architecture-samples/renovate.json at main · android/architecture-samples

Roughly summarized, here are the key points:

  • groupName: "kotlin" to bundle dependencies This setting specifies that the three elements—the Compose Compiler, Kotlin, and KSP—should be treated as belonging to the "same group." This allows Renovate to update them all together at once.
  • schedule: daily for a calm update pace This checks for updates once a day. You'll receive pull requests (PRs) on a daily basis, preventing a huge influx of dependency updates all at once, which makes things much easier to manage.
  • commitMessageExtra to see changes at a glance The version difference, like "2.0.10 → 2.0.20," is automatically added to the PR title. It's a small tweak, but surprisingly useful.

Setting up your configuration this way significantly reduces the tragedy of "Kotlin got updated, but Compose broke..."

 

🧑🏻‍💻 What We Found While Using It

Once this setup is in place, you can feel much more confident testing updates for everything Kotlin-related. Renovate diligently checks daily, automatically creating a PR whenever a new version drops.

But there's one small warning:

The Compose Compiler sometimes takes a little extra time to catch up to the latest Kotlin version. So, don't just merge the PR when you see it—it's highly recommended to verify the CI status first.

KSP is similar; because it depends on Kotlin's internal workings, it's safer to update it along with Kotlin and run your tests together.

 

🧑🏻‍💻 Summary: Teach Renovate that "These Three Are a Set"

The configuration we discussed treats the trio of Kotlin, the Compose Compiler, and KSP as a single group.

  • Bundle all Kotlin-related dependencies for simultaneous updates.
  • Check for updates at a manageable daily pace.
  • See version differences directly in the PR title.

Just implementing this significantly reduces the problems caused by versions getting out of sync and breaking your build.

💡 Key Takeaway: Use Renovate less as an "automatic update tool" and more as a "dependency rulebook."

We simply need to tell Kotlin, Compose, and KSP to cooperate and "work together."

👉 Kotlin・Compose・KSP の更新、どうしてこんなに面倒なの?


“Install Error(-10)” Got You Stuck? The Hidden Trick to Beat Google Play’s Pre-launch Test

 

🤔 Why the “App Not Owned” Error Happens

If your app fails the Google Play Pre-launch Test with this scary message —

u9.a: -10: Install Error(-10): The app is not owned by any user on this device.
An app is "owned" if it has been acquired from Play.

— you’re not alone.

This happens because the Pre-launch Test runs on Google’s own test devices, which aren’t linked to your Play account or purchase history.
So, if your app uses Play Core libraries (like AppUpdateManager or AppReviewManager), the “ownership check” fails, and your app never even gets installed.

It’s one of those bugs that make you scream: “But it works fine on my phone!” 😩

 

🤔 The Secret Fix Google Never Told You

Here’s the insider trick that devs have quietly been using:


Settings.System.getString(context.contentResolver, "firebase.test.lab")

This line reveals whether your app is currently running inside Firebase Test Lab — the same environment used for Pre-launch Tests.
If the value is "true", you’re in a test device.
That means you can safely skip anything that requires Play services or user ownership checks.

Here’s how to use it:


val isTestLab = Settings.System.getString(context.contentResolver, "firebase.test.lab") == "true"
if (!isTestLab) {
    // Run Play Core logic only in real user environments
}

Boom. 💣
No more random -10 install errors.
Your Pre-launch Test will finally pass like a charm.

 

⚡ Summary

The “Install Error(-10)” is not a bug in your code — it’s a Play Console quirk.
By detecting the Test Lab environment with:


Settings.System.getString(context.contentResolver, "firebase.test.lab")

you can bypass Play-related ownership checks and let your app install smoothly during the Pre-launch Test.

A single line of code could be the difference between “Test failed 🚫” and “Release ready ✅” — now that’s a win worth sharing.

👉 Firebase Test Lab × リリース前レポート環境を見分けるKotlin実装