一键导入
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 职业分类
Expert checklist and prompts for auditing and fixing Android accessibility issues, especially in Jetpack Compose.
Expert guidance on setting up and maintaining a modern Android application architecture using Clean Architecture and Hilt. Use this when asked about project structure, module setup, or dependency injection.
Authoritative rules and patterns for production-quality Kotlin Coroutines onto Android. Covers structured concurrency, lifecycle integration, and reactive streams.
Guidance on implementing the Data Layer using Repository pattern, Room (Local), and Retrofit (Remote) with offline-first synchronization.
Production-ready scripts for Android app testing, building, and automation. Provides semantic UI navigation, build automation, log monitoring, and emulator lifecycle management. Optimized for AI agents with minimal token output.
Expert guidance on setting up scalable Gradle build logic using Convention Plugins and Version Catalogs.
| 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.