When to activate
- Building Android apps with Jetpack Compose
- Implementing MVVM architecture with ViewModel and StateFlow
- Setting up Room database for local persistence
- Configuring Hilt for dependency injection
- Implementing Material 3 design system
When NOT to use
- For cross-platform apps (use react-native-expo or flutter-widgets)
- For iOS-only development
- For legacy XML-based Android UI
Instructions
- Project structure. Feature modules:
:feature:auth,:feature:feed,:core:data,:core:domain,:core:ui. - Jetpack Compose UI. Stateless composables with state hoisting. Use
rememberfor local,ViewModelfor screen-level,DataStorefor persistent. - ViewModel + StateFlow. Expose
StateFlow<UiState>from ViewModel. Usesealed class UiStatefor loading/success/error states. - Room database.
@Entityfor tables,@Daofor queries,@Databasefor setup. Use Flow return types for reactive queries. - Hilt DI.
@HiltAndroidAppon Application,@AndroidEntryPointon Activities,@Injectfor constructor injection. - Navigation. Navigation Compose with type-safe routes.
NavHostwith composable destinations. Deep link support vianavDeepLink. - Performance.
LazyColumn/LazyRowfor lists,derivedStateOfto avoid recomputation,keyfor stable identities in lists.
Example
@HiltViewModel
class FeedViewModel @Inject constructor(
private val repository: FeedRepository
) : ViewModel() {
private val _uiState = MutableStateFlow<FeedUiState>(FeedUiState.Loading)
val uiState: StateFlow<FeedUiState> = _uiState.asStateFlow()
fun loadFeed() {
viewModelScope.launch {
repository.getFeed()
.catch { _uiState.value = FeedUiState.Error(it.message) }
.collect { posts -> _uiState.value = FeedUiState.Success(posts) }
}
}
}
sealed class FeedUiState {
object Loading : FeedUiState()
data class Success(val posts: List<Post>) : FeedUiState()
data class Error(val message: String?) : FeedUiState()
}