一键导入
android-viewmodel
Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Koog 开发工具包:梳理 Tools/MCP/Prompt/LLM 参数/记忆/压缩/审核等规范并产出模板。用户提到 Koog、ToolRegistry、MCP、AskUser、ChatMemory 时调用。
将当前分支重组为一组小而清晰、适合代码评审的语义化提交。用户要求拆分提交、整理 commit 历史、重做提交顺序时调用。
Complete guide for BaseKit Network module, including Coroutines support (KCHttp), error handling, HTTPS, SSE, and caching strategies.
Expert guidance on setting up scalable Gradle build logic using Convention Plugins and Version Catalogs.
Solutions for common Android Gradle build errors. Invoke when encountering build failures, duplicate file conflicts, manifest merger issues, or dependency resolution errors.
Guide for Jetpack Navigation 3 in Compose. Invoke when user asks to set up Navigation 3, manage back stack, or use NavDisplay.
| name | android-viewmodel |
| description | Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events. |
Use ViewModel to hold state and business logic. It must outlive configuration changes.
Loading, Success(data), Error).StateFlow<UiState>.StateFlow backing a private MutableStateFlow.
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
.update { oldState -> ... } for thread safety.SharedFlow<UiEvent>.replay = 0 to prevent events from re-triggering on screen rotation.
private val _uiEvent = MutableSharedFlow<UiEvent>(replay = 0)
val uiEvent: SharedFlow<UiEvent> = _uiEvent.asSharedFlow()
.emit(event) (suspend) or .tryEmit(event).collectAsStateWithLifecycle() for StateFlow.
val state by viewModel.uiState.collectAsStateWithLifecycle()
For SharedFlow, use LaunchedEffect with LocalLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) within a coroutine.viewModelScope for all coroutines started by the ViewModel.