# Saved State & @CrowApp (https://crow.build/docs/core/saved-state)

Android can kill your background process at any moment. Crow eliminates `SavedStateHandle`, manual Bundle keys, and boilerplate `Activity`/`Application` classes.

## Zero-Key `saved()` [#zero-key-saved]

Replace `signal(initial)` with `saved(initial)` for any UI state that should survive configuration changes and OS process death:

```kotlin
@Ui
fun SearchScreen() {
    var query by saved("")
    var selectedCategory by saved("all")
    var recentSearches by saved(listOf("Kotlin", "Crow"))

    // Use them identically to signal() — compiled into fine-grained state
    // and automatically persisted to the saved-state Bundle.
}
```

`crow-compiler` synthesizes a stable, declaration-scoped key for every `saved()` call automatically — no hand-written string keys required. When mounting repeated stateful instances (such as inside a `For` loop or shared tab component), wrap each instance in `savedKey("section") { ... }` or use `savedState("custom_key", initial)`.

## Zero-Boilerplate Entry Point with `@CrowApp` [#zero-boilerplate-entry-point-with-crowapp]

With the `crow.app` Gradle plugin, you annotate your root `@Ui` function with `@CrowApp`. Crow generates a zero-AndroidX `CrowActivity` and `CrowApplication`, wires edge-to-edge insets, predictive back, saved state, and your manifest `<activity>` automatically.

```kotlin title="AppEntry.kt"
@CrowApp(label = "Notes", process = NotesStore::class)
@Ui
fun NotesApp(@Once store: NotesStore) {
    NotesRoot(store = store)
}
```

### Progressive Process Tiers [#progressive-process-tiers]

Choose exactly as much process control as your app needs:

| Tier | How you declare it | What you get |
| --- | --- | --- |
| **Tier 1** | `@CrowApp(label = "MyApp")` | Generated `CrowActivity` & manifest, zero boilerplate |
| **Tier 2A** | `@CrowApp(label = "MyApp", process = AppStore::class)` | Process-scoped object created once per OS process and injected into your root `@Ui` |
| **Tier 2B** | Standalone `@CrowApplication` | Custom process bootstrap shared across Activities, Workers, and Services |
| **Tier 3** | Subclass `CrowApplication` / `CrowActivity` | Full manual hooks when integrating legacy Android SDKs |

## `ProcessHost` [#processhost]

Every `@CrowApp` exposes a `ProcessHost` with:

- **`isForeground: Read<Boolean>`** — reactive foreground/background signal with zero AndroidX `ProcessLifecycleOwner` dependency.
- **`isMainProcess` & `processName`** — zero-IPC process identity checks.
- **`ProcessKey<T>`** — a thread-safe capability registry (`getOrPut`) for sharing stores, query clients, and platform services across your app.
- **`TestAppHost` & `TestProcessHost`** — deterministic drop-in fakes for JVM unit tests.

For durable disk persistence of app data and preferences across cold kills, pair `@CrowApp(process = ...)` with [`crow-store`](/docs/stack/store).