# Quickstart (https://crow.build/docs/quickstart)

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 [#your-first-crow-app]

```kotlin title="src/main/kotlin/com/example/counter/App.kt"
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"? [#what-happens-when-you-tap-add]

Trace the exact execution path when `count += step` runs:

<Steps>
<Step>
### `CounterScreen()` does NOT re-run [#counterscreen-does-not-re-run]

Unlike recomposition-based frameworks, `CounterScreen` ran **once** when mounted. Its `Column`, `Row`, `Button`, and `FilledTonalButton` are never revisited.
</Step>

<Step>
### The K2-compiled `LocalGraph` fires directly [#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 `TextNode`s.
</Step>

<Step>
### Only the two text nodes re-record [#only-the-two-text-nodes-re-record]

Crow UI's incremental layout re-measures only the dirty `TextNode`s. If their widths don't change, nothing else even moves.
</Step>
</Steps>

## Hosting Manually in an Existing Activity [#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`:

```kotlin title="MainActivity.kt"
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 [#next-steps]

<Cards>
<Card title="Signals & Reactivity" description="Learn signal(), val x by { }, split effects, and CR1001/CR1002 compiler rules." href="/docs/core/reactivity" />

<Card title="Headless UI Testing" description="Test CounterScreen on the JVM in milliseconds with deterministic frames and PNGs." href="/docs/guides/testing" />
</Cards>