Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

implementing-android-code

FreeNo executable scriptsNot checked

This skill should be used when implementing Android code in Bitwarden. Covers critical patterns, gotchas, and anti-patterns unique to this codebase. Triggered…

bitwardenby bitwarden★ 9,728 GitHub stars

About this skill

Implementing Android Code - Bitwarden Quick Reference

This skill provides tactical guidance for Bitwarden-specific patterns. For comprehensive architecture decisions and complete code style rules, consult docs/ARCHITECTURE.md and docs/STYLE_AND_BEST_PRACTICES.md.


Critical Patterns Reference

A. ViewModel Implementation (State-Action-Event Pattern)

All ViewModels follow the State-Action-Event (SAE) pattern via BaseViewModel<State, Event, Action>.

Key Requirements:

  • Annotate with @HiltViewModel
  • ViewModels that need navigation arguments receive their route via assisted injection (@HiltViewModel(assistedFactory = ...), @AssistedInject constructor(@Assisted route: XGraph.XRoute))
  • State class MUST be @Parcelize data class : Parcelable
  • Implement handleAction(action: A) - MUST be synchronous
  • Post internal actions from coroutines using sendAction()
  • Save/restore state via SavedStateHandle[KEY_STATE]
  • Private action handlers: private fun handle* naming convention

Template: See ViewModel template

Pattern Summary:

@HiltViewModel
class ExampleViewModel @Inject constructor(
    savedStateHandle: SavedStateHandle,
    private val repository: ExampleRepository,
) : BaseViewModel<ExampleState, ExampleEvent, ExampleAction>(
    initialState = savedStateHandle[KEY_STATE] ?: ExampleState(),
) {
    init {
        stateFlow.onEach { savedStateHandle[KEY_STATE] = it }.launchIn(viewModelScope)
    }

    override fun handleAction(action: ExampleAction) {
        // Synchronous dispatch only
        when (action) {
            is Action.Click -> handleClick()
            is Action.Internal.DataReceived -> handleDataReceived(action)
        }
    }

    private fun handleClick() {
        viewModelScope.launch {
            val result = repository.fetchData()
            sendAction(Action.Internal.DataReceived(result))  // Post internal action
        }
    }

    private fun handleDataReceived(action: Action.Internal.DataReceived) {
        mutableStateFlow.update { it.copy(data = action.result) }
    }
}

ViewModel with navigation arguments (assisted injection):

@HiltViewModel(assistedFactory = ExampleViewModel.Factory::class)
class ExampleViewModel @AssistedInject constructor(
    @Assisted route: ExampleGraph.ExampleRoute,
    savedStateHandle: SavedStateHandle,
    private val repository: ExampleRepository,
) : BaseViewModel<ExampleState, ExampleEvent, ExampleAction>(
    initialState = savedStateHandle[KEY_STATE] ?: ExampleState(userId = route.userId),
) {
    /**
     * Factory for creating an [ExampleViewModel] for a specific [ExampleGraph.ExampleRoute].
     */
    @AssistedFactory
    interface Factory {
        /**
         * Creates an [ExampleViewModel] for the given [route].
         */
        fun create(route: ExampleGraph.ExampleRoute): ExampleViewModel
    }
    // ...
}

Reference:

  • ui/src/main/kotlin/com/bitwarden/ui/platform/base/BaseViewModel.kt (see handleAction method)
  • app/src/main/kotlin/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt (see class declaration)
  • app/src/main/kotlin/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt (assisted injection of the route)

Critical Gotchas:

  • ❌ NEVER update mutableStateFlow directly inside coroutines
  • ✅ ALWAYS post internal actions from coroutines, update state in handleAction()
  • ❌ NEVER forget @IgnoredOnParcel for sensitive data (causes security leak)
  • ✅ ALWAYS use @Parcelize on state classes for process death recovery
  • ✅ State restoration happens automatically if properly saved to SavedStateHandle

B. Navigation Implementation (Navigation 3, Type-Safe)

All navigation uses Navigation 3 with type-safe @Serializable routes. Every NavDisplay displays one navigation graph: a @Serializable sealed class {Name}Graph : NavKey whose nested subclasses are its routes (e.g. AuthGraph.LoginRoute). The back stack is owned by a NavigationController<{Name}Graph> (ui/.../platform/navigation/NavigationController.kt); never touch a NavBackStack directly. A route may host a nested graph (e.g. RootNavGraph.AuthRoute hosts the AuthGraph, each nav bar tab hosts its own graph).

Pattern Structure:

  1. @Serializable route nested in the graph of the NavDisplay that shows the screen, holding every argument (any @Serializable type)
  2. EntryProviderScope<{Name}Graph>.{screen}Destination() extension that adds the entry, declares its transitions in metadata, and creates the ViewModel for the route (assisted injection)
  3. NavigationController<{Name}Graph>.navigateTo{Screen}() extension for navigation calls
  4. Groups of related destinations (a "flow") are added with EntryProviderScope<{Name}Graph>.{flow}Destinations(navigationController), and a route hosting a nested graph is added with
Full SKILL.md on GitHub

Install implementing-android-code in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

templates.md

FAQ

What does the implementing-android-code skill do?

This skill should be used when implementing Android code in Bitwarden. Covers critical patterns, gotchas, and anti-patterns unique to this codebase. Triggered by "How do I implement a ViewModel?", "Create a new screen", "Add navigation", "Write a repository", "BaseViewModel pattern", "State-Action-Event", "type-safe navigation", "@Serializable route", "SavedStateHandle persistence", "process death recovery", "handleAction", "sendAction", "Hilt module", "Repository pattern", "implementing a screen", "adding a data source", "handling navigation", "encrypted storage", "security patterns", "Clock injection", "DataState", or any questions about implementing features, screens, ViewModels, data sources, or navigation in the Bitwarden Android app.

How do I install the implementing-android-code skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the implementing-android-code skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare implementing-android-code with