Quickstart
Build a real reactive Android app with @CrowApp, fine-grained signals, derived state, and process-death persistence in 5 minutes.
With crow.app and @CrowApp, you do not need to write a MainActivity, an Application subclass, or <activity> XML in AndroidManifest.xml. Your @Ui function is the entire entry point.
Your First Crow App
package com.example.counter
import crow.material3.Button
import crow.material3.FilledTonalButton
import crow.material3.MaterialTheme
import crow.material3.Surface
import crow.runtime.CrowApp
import crow.runtime.Ui
import crow.runtime.saved
import crow.signals.getValue
import crow.signals.setValue
import crow.signals.signal
import crow.ui.Alignment
import crow.ui.Arrangement
import crow.ui.Column
import crow.ui.Modifier
import crow.ui.Row
import crow.ui.Text
import crow.ui.dp
import crow.ui.fillMaxSize
import crow.ui.padding
import crow.ui.safeDrawingPadding
@CrowApp(label = "Counter")
@Ui
fun CounterApp() {
MaterialTheme {
Surface(Modifier.fillMaxSize()) {
CounterScreen()
}
}
}
@Ui
fun CounterScreen() {
// Process-death surviving state — the K2 compiler assigns a stable key automatically.
var count by saved(0)
// Pure in-memory fine-grained signal — compiled into a LocalGraph field.
var step by signal(1)
// Memoized derived value — recomputes only when `count` or `step` changes.
val nextValue by { count + step }
Column(
modifier = Modifier
.fillMaxSize()
.safeDrawingPadding()
.padding(24.dp),
verticalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text("Count: $count", style = MaterialTheme.typography.displaySmall)
Text("Next tap reaches $nextValue", style = MaterialTheme.typography.bodyLarge)
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Button(onClick = { count += step }) {
Text("Add $step")
}
FilledTonalButton(onClick = { step = if (step == 1) 5 else 1 }) {
Text("Step: $step")
}
}
}
}What Happens When You Tap "Add"?
Trace the exact execution path when count += step runs:
CounterScreen() does NOT re-run
Unlike recomposition-based frameworks, CounterScreen ran once when mounted. Its Column, Row, Button, and FilledTonalButton are never revisited.
The K2-compiled LocalGraph fires directly
count writes to its generated field, nextValue marks dirty lazily, and the batched flush writes the two new strings directly into the two TextNodes.
Only the two text nodes re-record
Crow UI's incremental layout re-measures only the dirty TextNodes. If their widths don't change, nothing else even moves.
Hosting Manually in an Existing Activity
If you prefer an explicit Activity (or are embedding Crow into an existing app), host any @Ui tree inside CrowView:
class MainActivity : Activity() {
private lateinit var host: CrowView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidScheduler.install()
host = CrowView(this)
setContentView(host)
host.setContent { CounterApp() }
}
}Next Steps
How is this guide?