implementing-android-code
FreeNo executable scriptsNot checkedThis skill should be used when implementing Android code in Bitwarden. Covers critical patterns, gotchas, and anti-patterns unique to this codebase. Triggered…
by bitwarden★ 9,728 GitHub starsAbout 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(seehandleActionmethod)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
mutableStateFlowdirectly inside coroutines - ✅ ALWAYS post internal actions from coroutines, update state in
handleAction() - ❌ NEVER forget
@IgnoredOnParcelfor sensitive data (causes security leak) - ✅ ALWAYS use
@Parcelizeon 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:
@Serializableroute nested in the graph of theNavDisplaythat shows the screen, holding every argument (any@Serializabletype)EntryProviderScope<{Name}Graph>.{screen}Destination()extension that adds theentry, declares its transitions in metadata, and creates the ViewModel for the route (assisted injection)NavigationController<{Name}Graph>.navigateTo{Screen}()extension for navigation calls- 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
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
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
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
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic