DEV Community

ReClaim
ReClaim

Posted on AI-assisted

Asking without nagging on an Android Home screen: save the quiet period first, show one card at a time

We're building ReClaim, a minimalist Android launcher that's on Google Play. A launcher gets opened all day. Every Home press and every back-out of an app lands on it. That makes it a tempting place to ask for things, and a terrible place to ask badly.

We ask two things on Home. One is a short "Do you like ReClaim?" card. The other is a "Back up your settings" card for people who aren't signed in, which offers to create an account so a new phone can restore their setup. This post is about the timing code behind both: how we count use, why the quiet period is written before a card appears, how a sign-in that lands mid-decision is handled, and how the two cards avoid stacking on top of each other.

This code is in a November commit on our master branch. The live Play listing still shows version 0.6.6.0.1, updated October 29, 2026, and the repo is at 0.6.7.3.1, so treat this as the next build's behavior. We haven't confirmed which parts, if any, are already in the Play release. Stack: Kotlin, Jetpack Compose, Hilt, Preferences DataStore. All code below is copied from the repo.

Count days, not opens

The first rule is that opening the launcher fifty times on day one shouldn't count as fifty uses. Both cards count distinct local days instead. Here is the account card's policy, which is a plain object with no Android imports:

internal object AccountPromptPolicy {
    const val DAYS_BEFORE_ASK = 2
    const val QUIET_DAYS = 4L

    fun shouldAsk(state: AccountPromptState, today: Long, signedIn: Boolean): Boolean {
        if (signedIn) return false
        if (state.daysUsed < DAYS_BEFORE_ASK) return false
        val next = state.nextAsk ?: return true
        return today >= next
    }

    /** Keeps at most [DAYS_BEFORE_ASK] distinct days. A day already stored stays as it is. */
    fun rememberedDays(existing: Set<String>, epochDay: Long): Set<String> {
        val day = epochDay.toString()
        if (day in existing || existing.size >= DAYS_BEFORE_ASK) return existing
        return existing + day
    }

    /** A quiet period only moves later. */
    fun laterQuietDay(current: Long, requested: Long): Long =
        if (requested > current) requested else current
}
Enter fullscreen mode Exit fullscreen mode

daysUsed is the size of a set of epoch-day strings, written from LocalDate.now().toEpochDay(). Because the card only needs to know "has this person used the launcher on two different days," the set never grows past two entries. rememberedDays returns the same set once it's full, and the store only writes when the set actually changed. A unit test walks it through days 10, 10, 11 and 12 and expects {"10", "11"} at the end.

The feedback card uses the same idea with different numbers:

internal object FeedbackPolicy {
    const val DAYS_BEFORE_ASK = 3
    const val SNOOZE_DAYS = 7L
    const val MAX_ASKS = 3

    fun shouldAsk(state: FeedbackState, today: Long): Boolean {
        if (state.finished || state.asks >= MAX_ASKS) return false
        val snooze = state.snoozeUntil
        if (snooze != null && today < snooze) return false
        return state.daysUsed >= DAYS_BEFORE_ASK
    }
}
Enter fullscreen mode Exit fullscreen mode

It waits for three distinct days, and it has two things the account card doesn't: a hard cap of three showings in total, and a finished flag that turns it off for good once someone completes it. Its store keeps up to eight day strings, more than it needs. Only the count matters, so the extra entries are harmless.

Both policies are pure functions on purpose, so "ask or not" is tested on the JVM with plain numbers for days: quiet before day two or three, quiet during a snooze, asking again on the day the snooze ends, and stopping after the third ask.

Save the quiet period before the card appears

This is the part we'd most recommend to anyone building a prompt. Here is the account controller's entry point:

    suspend fun onHomeVisible(feedbackOpen: Boolean) {
        gate.withLock {
            if (_visible.value) return
            val epochDay = today()
            val state = store.recordDay(epochDay)
            if (!AccountPromptPolicy.shouldAsk(state, epochDay, signedIn())) return
            if (signedIn()) return
            if (feedbackOpen) {
                store.quietUntil(epochDay + 1)
                return
            }
            store.quietUntil(epochDay + AccountPromptPolicy.QUIET_DAYS)
            // A sign-in that lands while the quiet day is saved stays off the screen.
            if (signedIn()) return
            _visible.value = true
        }
    }
Enter fullscreen mode Exit fullscreen mode

The order matters. When the policy says yes, the controller first writes the next allowed day (today plus four) to DataStore, and only then flips _visible to true. Dismissing the card writes nothing at all. dismiss() just sets _visible back to false.

A launcher's dialogs get interrupted constantly: the user presses Home, the system kills the process, the phone reboots. If the quiet period were written when the user tapped "Not now," every one of those interruptions would leave no record, and the card would come back on the next open, possibly minutes later. Writing it first means the worst case is a card that was shown once and then not again for four days, which is what we wanted anyway.

The feedback controller does the same thing in its own words:

    suspend fun onHomeVisible() {
        gate.withLock {
            if (_ui.value != null) return
            val today = LocalDate.now().toEpochDay()
            val state = store.recordDay(today)
            if (!FeedbackPolicy.shouldAsk(state, today)) return
            store.noteShown(today + 1)
            ratingRecorded = false
            savedNote = null
            _ui.value = FeedbackUi(FeedbackStep.Like, forced = false)
        }
    }
Enter fullscreen mode Exit fullscreen mode

noteShown(today + 1) increments the ask count and sets a snooze to tomorrow before the card appears. If the card is ignored or the process dies, the feedback card can come back the next day, but each showing uses up one of its three asks. An explicit "Not now" (or dismissing the dialog) pushes the snooze out to seven days:

    fun notNow() {
        val current = _ui.value ?: return
        if (current.busy) return
        if (current.step is FeedbackStep.Thanks) {
            _ui.value = null
            return
        }
        _ui.value = null
        if (!current.forced) {
            appScope.launch { store.snoozeUntil(LocalDate.now().toEpochDay() + FeedbackPolicy.SNOOZE_DAYS) }
        }
    }
Enter fullscreen mode Exit fullscreen mode

The forced check is for a preview mode: long-pressing the version line in Settings opens the card on demand so we can test it without waiting three days, and that path never touches the stored snooze.

A quiet period only moves later

The account store has one more guard. Different callers ask for different quiet periods: four days after a showing, one day when the feedback card is already up (more on that below). If a one-day request ever landed after a four-day one, it would cut the quiet period short. In today's call paths that shouldn't happen, because the policy already says no until the saved day arrives, but the store doesn't rely on callers getting the order right. It refuses to move the date earlier:

    override suspend fun quietUntil(epochDay: Long) {
        store.edit { prefs ->
            val current = prefs[Keys.NEXT_ASK] ?: 0L
            val later = AccountPromptPolicy.laterQuietDay(current, epochDay)
            if (later != current) prefs[Keys.NEXT_ASK] = later
        }
    }
Enter fullscreen mode Exit fullscreen mode

The comparison happens inside edit, which matters. The DataStore guide says of updateData (which edit is built on for Preferences DataStore): "All of the code in the updateData block is treated as a single transaction." Reading the current value outside the block and writing inside it would open a window for a lost update. recordDay, by contrast, reads first and edits second, but it only ever runs under the controller's Mutex, so there's no second writer to race.

Both stores also say in their KDoc that this history is "Device-local prompt history. It is not part of the account backup." So restoring a ReClaim account onto a new phone starts the counts over, which seemed right. One thing we noticed while writing this: the app's Android backup rules only exclude the account session file, so these DataStore files aren't excluded from Android's own cloud backup or device transfer. Depending on how the new phone is set up, the history may come along anyway. We haven't checked which happens in practice.

When the user signs in mid-decision

The account card should never be visible while someone is signed in. That has two halves. The first is a collector on the sign-in flow, started in the controller's init:

    init {
        appScope.launch {
            signIns.collect { isSignedIn ->
                if (isSignedIn) gate.withLock { _visible.value = false }
            }
        }
    }
Enter fullscreen mode Exit fullscreen mode

It takes the same lock as onHomeVisible, so it can't interleave with a decision halfway through. The second half is the extra signedIn() checks inside onHomeVisible. There are three of them, and the last one runs after the DataStore write. The write suspends, and a sign-in that completes during that suspension would otherwise be followed by the card appearing anyway. There's a test for exactly that, using a fake store that signs the user in as a side effect of saving the quiet day:

        val store = object : AccountPromptHistory {
            override suspend fun recordDay(epochDay: Long): AccountPromptState = memory.recordDay(epochDay)
            override suspend fun quietUntil(epochDay: Long) {
                memory.quietUntil(epochDay)
                signedIn.value = true
            }
        }
Enter fullscreen mode Exit fullscreen mode

With that fake, the second day's onHomeVisible must leave visible false. The constructor takes signedIn, signIns, the store, a scope and a today function as plain parameters, with a separate @Inject constructor for Hilt. That split keeps a test like this to a few lines.

One card at a time

Two independent controllers, each with its own rules, will eventually both say yes on the same Home visit. We didn't want a feedback dialog with a backup dialog stacked behind it. The sequencing lives in a small class in the UI layer:

/**
 * Feedback decides first. The account card follows only on the home screen,
 * and a card already on screen keeps the other one from starting.
 */
internal class HomePromptSequence(
    private val accountVisible: () -> Boolean,
    private val decideFeedback: suspend () -> Boolean,
    private val route: () -> String?,
    private val onAccount: suspend (feedbackOpen: Boolean) -> Unit,
) {
    private val gate = Mutex()

    suspend fun consider(ready: Boolean) {
        if (!ready) return
        gate.withLock {
            if (accountVisible()) return
            val feedbackOpen = decideFeedback()
            if (!accountPromptOnLauncher(route())) return
            if (accountVisible()) return
            onAccount(feedbackOpen)
        }
    }
}

/** The account card is for the home screen. A route that is not ready yet counts as home. */
internal fun accountPromptOnLauncher(route: String?): Boolean =
    route == null || route == Routes.LAUNCHER
Enter fullscreen mode Exit fullscreen mode

Feedback decides first. If an account card is already on screen, nothing starts. If the feedback card just opened, the account controller is still called, but with feedbackOpen = true, and in that case it saves a quiet period of one day and returns without showing. The account card comes back tomorrow instead of today. A test checks that: on day 11 with the feedback card open, nextAsk becomes 12, a second visit that day stays quiet, and on day 12 the card shows and moves nextAsk to 16.

There are three locks involved here: the sequence's gate, the feedback controller's gate, and the account controller's gate. kotlinx.coroutines' Mutex documentation is direct about one property: "It is non-reentrant, that is invoking lock even from the same thread/coroutine that currently holds the lock still suspends the invoker." So the sequence holds its own gate while calling into the controllers, and each controller takes a different one. None of them ever calls back into a lock it already holds. If we'd shared one lock across all three to "simplify," the first consider call would suspend forever on itself.

The sequence's gate also means two Home visits in quick succession share one decision. A test starts one consider, holds the feedback decision open with a CompletableDeferred, starts a second, and checks that the second waits and the feedback decision ran once.

What "Home is visible" actually means

The wiring lives in the root composable:

    val promptSequence = remember {
        HomePromptSequence(
            accountVisible = { accountPromptViewModel.visible.value },
            decideFeedback = {
                feedbackViewModel.awaitHomeVisible()
                feedbackViewModel.ui.value != null
            },
            route = { navController.currentBackStackEntry?.destination?.route },
            onAccount = { feedbackOpen -> accountPromptViewModel.onHomeVisible(feedbackOpen) },
        )
    }
    val considerPrompts: () -> Unit = {
        val ready = tutorialCompleted == true && !showSetupGate
        promptScope.launch { promptSequence.consider(ready) }
    }
    LaunchedEffect(Unit) { setupViewModel.refresh(context) }
    LaunchedEffect(tutorialCompleted, showSetupGate) { considerPrompts() }
    DisposableEffect(lifecycleOwner, tutorialCompleted, showSetupGate) {
        val observer = LifecycleEventObserver { _, event ->
            if (event == Lifecycle.Event.ON_RESUME) {
                setupViewModel.refresh(context)
                considerPrompts()
            }
        }
        lifecycleOwner.lifecycle.addObserver(observer)
        onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
Enter fullscreen mode Exit fullscreen mode

ready keeps both cards away until the tutorial is done and the setup gate (which we wrote about in the setup gate post) is out of the way. After that, considerPrompts runs on every ON_RESUME of the activity.

That's where the names are a little optimistic. ON_RESUME fires whatever screen the navigation graph is on, so the feedback decision runs on Settings too. One of the tests, settings_leavesTheAccountCardAlone, shows exactly that: feedback is decided and the account card isn't. Only the account card checks the route, and a route that isn't known yet counts as home. In practice, a feedback card can open over Settings. That's acceptable for a card capped at three showings, but onHomeVisible is not a precise name.

What isn't solved yet

Some honest gaps, all from reading the code:

  • The account card has no cap. Feedback stops after three asks. The account card comes back every four days until the person signs in. There is no "don't ask again." That's the next thing we'd change.
  • Other dialogs aren't in the sequence. The restore offer, the missing-apps notice after a restore, and the hide-import notice are separate dialogs in the root composable. "One card at a time" is only true between these two.
  • Days are wall-clock days. Everything uses LocalDate.now(). Setting the phone's date forward a year and then back would save a quiet day far in the future, and since quiet periods only move later, the card would stay away for that long. Moving the date back just delays a card. Neither is harmful, but neither is "correct" either.
  • Dismissing and "Not now" are the same for the account card. We can't tell "I'll do it later" from "stop asking," which is part of why the missing cap matters.
  • Testing. The policy, store, controller and sequence have JVM tests with an in-memory DataStore. The Compose dialogs and the ON_RESUME wiring don't have instrumented tests, and we haven't run this exact flow on a device for this post.

Takeaways

  • Count distinct days, not opens. A launcher gets opened far too often for an open count to mean anything.
  • Write the quiet period before you show the card. Interruptions are normal, and a card that only records "Not now" will come back after every one of them.
  • Make quiet periods only move later, and do the compare inside the DataStore transaction.
  • Re-check the condition that should hide the card after every suspension point, and test it with a fake that changes the world mid-call.
  • Sequence your prompts in one place, and give each component its own non-reentrant lock.

ReClaim is free on Google Play. The account backup that card offers builds on the snapshot code we described in backup and restore for an Android launcher with Room. If you're curious about the product side of keeping a Home screen quiet, our guide to designing a minimal Android home screen covers it from the user's end.

This post was drafted with AI assistance and reviewed by the ReClaim team.

Top comments (0)