We're building ReClaim, a minimalist Android launcher that's on Google Play. The first time it opens, it shows a short tutorial. The tutorial doesn't just explain features. It asks which apps pull you in, lets you hide or block them, picks what goes on your Home screen, and sets two shortcuts.
The design choice behind it is simple: the tutorial changes the real app as you go. There's no draft state and no "apply everything" button at the end. That one rule shaped most of the code, and it caused a few problems we had to solve. This post walks through them: how the steps are modeled, where the app suggestions come from, how a skip can keep a decision, why the recap is built from a diff, and where the tutorial sits relative to the permission screen.
A version note first. The code below is from our repository at its current commit, where versionName is 0.6.7.3.1. The Play listing now shows 0.6.8.1.1, updated December 1, 2026, which is newer than that snapshot. Its release notes are about block screens, not the tutorial, but I haven't checked the shipped tutorial on a device for this post, so read this as a walkthrough of the repo code.
1. The steps are an enum, and the recap is three sets
The tutorial's state lives in one Hilt ViewModel. The steps are a plain enum:
/** The tutorial's ordered steps. [ordinal] doubles as the progress position. */ enum class TutorialStep(val title: String) { WELCOME("Welcome"), DISTRACTING("Distracting apps"), BLOCKING("Blocking"), FAVORITES("Home screen"), SHORTCUTS("Shortcuts"), GESTURES("Gestures"), FOLDERS("Folders"), DONE("All set"), } /** What the user did with an app during the tutorial, for the closing recap. */ data class TutorialTally( val hidden: Set<String> = emptySet(), val blocked: Set<String> = emptySet(), val favorited: Set<String> = emptySet(), ) The ordinal does double duty as the progress position. The header shows "Step 3 of 8" from index + 1 and entries.size, and the slide animation compares ordinals to decide whether to slide forward or rewind. Reordering steps means moving one line.
TutorialTally exists only for the last screen, which tells you what you did. It holds package names, not app objects, so it's cheap to copy on every update.
2. No draft state
The class comment states the contract:
/** * Drives the first-run tutorial. Every action here delegates to the same repositories the rest of * the app uses (hide, block, favorite, reminders, shortcuts) — the tutorial configures the real * launcher as the user walks through it rather than staging changes for a final commit, so * abandoning it midway still leaves everything already chosen in place. */ The other way to build onboarding is to collect choices in memory and commit them on the last screen. That gives you a clean "cancel" that undoes everything. It also gives you a commit step that has to be correct for every combination of choices, and a user who quits on step 6 of 8 loses everything they picked.
We went the other way. Each action calls the same repository function the rest of the launcher uses. Hiding apps in the tutorial is the same call as long-press → Hide:
/** Hides every selected app through the same path as the launcher's long-press → Hide. */ fun hideSelected(level: Int, challengeType: ChallengeType?) { val apps = selectedApps() if (apps.isEmpty()) return viewModelScope.launch { apps.forEach { appRepository.hide(it.packageName, level, challengeType) } _tally.update { it.copy(hidden = it.hidden + apps.map { app -> app.packageName }) } clearSelection() } } That has a few consequences:
- There's no tutorial-only code path to get wrong. If hiding works in the launcher, it works here. The hide also attaches a reminder by default, the same as everywhere else.
- Quitting keeps what you did. Someone who hides two apps and closes the tutorial still has two hidden apps.
- There's no "undo all". A change made on step 2 is real. Undoing it means going to Settings like you would for any other change. We accept that, because the tutorial only offers actions a user would take anyway.
- "Skip" and "Next" can be the same function. The footer wires both to
viewModel::next. A step only has side effects if you used it, so skipping is just moving on. The Skip button only appears on the four steps that can actually change something.
3. Where the suggestions come from
The second step asks "Which apps pull you in?" and shows a short list. The list comes from real usage when the app can read it, and from a curated list when it can't:
init { viewModelScope.launch { val apps = appRepository.allApps.first() val byPackage = apps.associateBy { it.packageName } val own = appRepository.ownPackageName val mostUsed = usageStatsSource.mostUsedPackages(days = 7, limit = 16) .mapNotNull { byPackage[it] } .filter { it.packageName != own } val fallback = apps.filter { it.packageName in COMMONLY_DISTRACTING } _candidates.value = mostUsed.ifEmpty { fallback }.take(12) } } mostUsedPackages sums foreground time from daily usage buckets:
suspend fun mostUsedPackages(days: Int = 7, limit: Int = 12): List<String> = withContext(Dispatchers.IO) { if (!hasPermission()) return@withContext emptyList() val end = System.currentTimeMillis() val start = end - days.toLong() * 24 * 60 * 60 * 1000 val stats = runCatching { usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, start, end) }.getOrNull().orEmpty() stats.filter { it.totalTimeInForeground > 0 } .groupBy { it.packageName } .mapValues { (_, v) -> v.sumOf { it.totalTimeInForeground } } .entries.sortedByDescending { it.value } .map { it.key } .take(limit) } A few details:
-
mapNotNull { byPackage[it] }drops anything you can't launch. Usage stats include system packages without a launcher icon.allAppsonly holds launchable apps, so those fall out here. ReClaim's own package is filtered out too. - It asks for 16 and shows 12. Because some of the top packages get dropped, asking for a few extra leaves room. That's our reading of the numbers; there's no comment on it.
- Daily buckets are fine for ranking. The
UsageStatsManagerreference warns that "The begin and end times of the time range may be expanded to the nearest whole interval period." So the "last 7 days" can cover part of an eighth. For daily limits we replay usage events instead of trusting the buckets, as we wrote about in our post on daily app limits. For "which apps do you use most?", a slightly wider window doesn't change the answer much.
Without Usage Access, mostUsedPackages returns an empty list and the fallback takes over. That's a fixed set of package names:
/** * Package names commonly blocked for focus. Used as a fallback ranking wherever real usage data * isn't available — Usage Access is optional, so both the Block screen's "block together" * suggestions and the first-run tutorial's "distracting apps" step need something sensible to * show without it. */ val COMMONLY_DISTRACTING: Set<String> = setOf( "com.instagram.android", "com.zhiliaoapp.musically", "com.facebook.katana", "com.twitter.android", "com.reddit.frontpage", "com.google.android.youtube", "com.snapchat.android", "com.pinterest", "com.facebook.orca", "com.netflix.mediaclient", ) The fallback only shows apps that are actually installed, because it filters allApps. The step's subtitle changes too. With access it says "Your most-used apps from the last 7 days." Without it, it says "Commonly distracting apps you have installed" and suggests turning on Usage access later. The screen reads the permission once, with remember, so granting access mid-tutorial won't re-rank the list. The candidates are also computed once, in init.
4. Embedding the real Block screen
Hiding applies right away. Blocking doesn't, because a block needs a length, and the launcher already has a screen for choosing one. So "Block" in step 2 only marks apps, and step 3 opens the real Block screen inside the tutorial:
// When set, the real Block screen takes over the whole surface for this target. var blockTarget by remember { mutableStateOf<AppInfo?>(null) } blockTarget?.let { target -> val blockViewModel: BlockViewModel = hiltViewModel() LaunchedEffect(target.packageName) { viewModel.snapshotBlockedBefore() blockViewModel.retarget(target.packageName, pendingBlock.map { it.packageName }.toSet()) } // Without this, back would fall through to the nav host underneath the tutorial and // silently navigate a screen the user can't even see. BackHandler { blockTarget = null } BlockScreen( onDone = { viewModel.recordBlocksApplied() blockTarget = null }, onSetLimitInstead = {}, viewModel = blockViewModel, showLimitShortcut = false, ) return } retarget points a BlockViewModel at the first marked app and pre-selects the rest. We added it because the tutorial shows the screen inline, so there's no navigation route to read the target from.
The BackHandler matters more than it looks. The reference describes it as "An effect for handling presses of the system back button." Without it here, Back would go to the navigation host under the tutorial overlay and change a screen the user can't see. With it, Back closes the Block screen and returns to the step.
5. A recap built from a diff
When the Block screen finishes, the tutorial needs to know what was blocked. It could trust the selection it passed in, but the user might have changed the selection, or backed out. So it compares before and after:
/** Snapshots what is already blocked so [recordBlocksApplied] can report only new blocks. */ fun snapshotBlockedBefore() { viewModelScope.launch { blockedBefore = blockRepository.activeBlocks.first().keys } } /** * Folds whatever the Block screen actually blocked into the tally. Diffing against the * snapshot rather than trusting the screen's selection is what makes cancelling free: backing * out blocks nothing, so the difference is empty and nothing is recorded. */ fun recordBlocksApplied() { viewModelScope.launch { val after = blockRepository.activeBlocks.first().keys val newlyBlocked = after - blockedBefore _tally.update { it.copy(blocked = it.blocked + newlyBlocked) } // Anything now blocked is no longer pending, so the step stops offering to block it. _pendingBlock.update { pending -> pending.filterNot { it.packageName in newlyBlocked } } } } Cancelling is free this way. If the user backs out, nothing new is blocked, the difference is empty, and the recap says nothing. The same diff clears those apps from the "Ready to block" list, so the step stops offering them.
One limit: the diff counts anything that became blocked between the snapshot and the check. In practice that's the Block screen's own confirm. It's still worth knowing what it measures.
6. A skip that keeps a decision
Here's the case that took the most thought. A user marks Instagram as "Block" in step 2. In step 3 they tap Next without opening the Block screen. What should happen?
Dropping the mark felt wrong, because the user already decided. So next() applies it:
/** Advances one step. Skipping is the same motion — a step only has side effects if used. */ fun next() { val steps = TutorialStep.entries val index = steps.indexOf(_step.value) // Marking an app to block is a decision the user already made a step earlier. Moving on // without opening the Block screen shouldn't quietly discard it, so the default duration // stands in for the length they never got around to choosing. if (_step.value == TutorialStep.BLOCKING) blockPendingAtDefaultDuration() if (index < steps.lastIndex) _step.value = steps[index + 1] } private fun blockPendingAtDefaultDuration() { val pending = _pendingBlock.value if (pending.isEmpty()) return // Cleared up front so a fast double-tap on Next can't queue the same block twice. _pendingBlock.value = emptyList() viewModelScope.launch { val minutes = settingsRepository.settings.first().defaultBlockDurationMinutes val until = System.currentTimeMillis() + minutes * 60_000L blockRepository.block(pending.map { it.packageName }, until) _tally.update { tally -> tally.copy(blocked = tally.blocked + pending.map { it.packageName }) } } } Two choices here:
- The user is told first. Under the "Choose how long" button, step 3 says "Move on without choosing and they'll be blocked for", followed by the user's default block length from Settings. Blocking silently would be the worst version of this.
- The pending list is cleared before the coroutine starts. A fast double tap on Next could otherwise run the block twice.
We found one gap while writing this. The X in the header leads to a "Skip the tutorial?" dialog, and confirming it does this:
if (showExitConfirm) { ExitConfirmDialog( onConfirm = { showExitConfirm = false viewModel.complete() onExit() }, onDismiss = { showExitConfirm = false }, ) } That marks the tutorial complete and leaves, but it doesn't apply pending blocks. So Next keeps the decision and Skip-the-tutorial drops it. You can argue either way for the X, since it's a deliberate exit. But the two paths don't agree, and the text under the button only talks about moving on. We'll pick one.
The tally line in blockPendingAtDefaultDuration also adds packages without checking the result. If the write failed, the recap would still count them.
7. Tutorial first, then permissions
ReClaim needs several special permissions, which we covered in the setup gate post. An earlier version showed that permission screen first and the tutorial after. The current code flips the order, and the decision is now one small function:
/** * First launch shows the tutorial, then the permission screen. * [tutorialCompleted] is null until the saved flag has been read, so neither cover flashes early. * Skipping the tutorial ([tutorialDeferred]) reveals the permission screen at once. */ internal fun firstRunCover( tutorialCompleted: Boolean?, tutorialDeferred: Boolean, permissionsMissing: Boolean, ): FirstRunCover = when { tutorialCompleted == null -> FirstRunCover.None !tutorialCompleted && !tutorialDeferred -> FirstRunCover.Tutorial permissionsMissing -> FirstRunCover.Permissions else -> FirstRunCover.None } Both covers are overlays drawn above the navigation host, not destinations, so Back can't land on them. The null case matters. The completed flag lives in DataStore, and RootViewModel starts it as null until the first read. Without that, a returning user could see the tutorial for a frame before the saved true arrives.
tutorialDeferred handles the other direction. Marking the tutorial complete is an async write, so after Skip the root sets an in-memory flag to drop the overlay right away. The unit tests cover that case:
@Test fun skip_showsPermissionsBeforeTheSavedFlagLands() { assertEquals( FirstRunCover.Permissions, firstRunCover(tutorialCompleted = false, tutorialDeferred = true, permissionsMissing = true), ) } Putting the tutorial first has a cost that follows from section 3. On a fresh install, Usage Access usually isn't granted yet, so the curated fallback is the common path, not the exception. Blocks made in the tutorial are written right away, and the launcher checks them before it opens an app. Blocking apps opened from anywhere else is the accessibility service's job, and that comes from the permission screen after the tutorial.
8. When it counts as done
complete() writes the flag. Its KDoc says it's "Only called from the final step," so quitting partway leaves the flag unset and the tutorial comes back on the next cold start. That's out of date: as section 6 shows, confirming the exit dialog calls complete() too. In the current code, the tutorial comes back only if the process dies before Finish or the exit dialog is confirmed. The behavior is reasonable. The comment needs updating.
Replaying from Settings → Support → Replay Tutorial goes through a normal navigation route with a fresh ViewModel. It doesn't reset the flag, so the recap only reflects that session. Apps you already hid can show up in the list again without a "Hidden" label, because the label comes from the session's tally, not the database.
Takeaways
- Apply changes as they happen. If onboarding uses the same repository calls as the rest of the app, there's no second code path to keep correct, and quitting never loses work.
- Make Skip and Next the same call. Then a step only has side effects if the user used it.
- Have a fallback for optional data. A curated list filtered to installed apps beats an empty screen when a permission is off.
- Build the recap from what happened. A before/after diff makes cancelling free and keeps the summary honest.
- If a skip keeps a decision, say so on screen. Then check that every exit path agrees.
- Model "not read yet" as its own state. A nullable flag stops onboarding from flashing for returning users.
If you want the product side of these choices, our guide to app limits vs. blocking vs. reminders explains when each one fits, and our guide to hiding apps on Android covers the hiding side from the user's end.
This post was drafted with AI assistance and reviewed by the ReClaim team.


