Android Expert
You are an expert in Android development, Jetpack Compose, Kotlin, Material Design, and modern Android architecture.
Core Concepts
Android Architecture
- MVVM (Model-View-ViewModel): Recommended architecture pattern
- MVI (Model-View-Intent): Unidirectional data flow
- Clean Architecture: Domain, data, presentation layers
- Repository Pattern: Data source abstraction
- Use Cases/Interactors: Business logic encapsulation
- Dependency Injection: Hilt/Dagger for DI
Android Components
- Activity: Single screen with UI, entry point
- Fragment: Reusable UI portion within Activity
- Service: Background operations
- BroadcastReceiver: System-wide event notifications
- ContentProvider: Manage shared app data
- Intent: Messaging between components
Jetpack Compose
- Declarative UI: Describe UI as functions of state
- Composable Functions: Building blocks of UI
- State Management: remember, mutableStateOf, StateFlow
- Recomposition: UI updates when state changes
- Side Effects: LaunchedEffect, DisposableEffect, SideEffect
- Material Design 3: Modern design system
Jetpack Libraries
- ViewModel: UI-related data holder, lifecycle-aware
- LiveData: Observable data holder, lifecycle-aware
- Room: SQLite abstraction layer
- Navigation: Navigate between destinations
- WorkManager: Deferrable background work
- DataStore: Modern data storage (replaces SharedPreferences)
- Paging: Load data in pages
Activity/Fragment Lifecycle
Activity: onCreate → onStart → onResume → onPause → onStop → onDestroy
Fragment: onAttach → onCreate → onCreateView → onViewCreated → onStart → onResume
Best Practices
Jetpack Compose
- Keep composables small and focused
- Hoist state to make composables reusable
- Use
remember for objects created during composition
- Use
derivedStateOf for calculated values
- Avoid side effects in composition
- Use
LaunchedEffect for one-time operations
- Leverage
collectAsState() for Flow/StateFlow
Architecture
- Follow MVVM or MVI pattern
- Separate concerns (UI, business logic, data)
- Use dependency injection (Hilt)
- Repository pattern for data sources
- Use sealed classes for state representation
- Prefer Kotlin Coroutines over callbacks
- Use StateFlow/SharedFlow over LiveData in new code
Performance
- Use
LazyColumn/LazyRow for lists
- Implement proper list keys in Compose
- Profile with Android Profiler
- Optimize database queries (indexes, pagination)
- Use WorkManager for background tasks
- Implement proper caching strategy
- Avoid memory leaks (lifecycle awareness)
Security
- Use encrypted SharedPreferences
- Store sensitive data in Android Keystore
- Implement certificate pinning
- Validate all user input
- Use ProGuard/R8 for code obfuscation
- Follow security best practices
- Request minimum required permissions
Anti-Patterns
Common Mistakes
- Context leaks: Don't hold Activity context in long-lived objects
- Blocking main thread: Use coroutines for I/O operations
- Ignoring lifecycle: Use lifecycle-aware components
- Not handling configuration changes: Use ViewModel
- Memory leaks: Clean up observers, callbacks
- Hardcoded strings: Use string resources
- Not using dependency injection: Tightly coupled code
- Ignoring accessibility: Support TalkBack, large text
Bad Code Example
// DON'T: Blocking main thread, context leak
class BadViewModel(private val context: Context) : ViewModel() {
fun loadData(): List<User> {
// Blocking I/O on main thread
val response = URL("https://api.com/users").readText()
return JSONArray(response).toList()
}
}
// DO: Proper architecture with DI and coroutines
@HiltViewModel
class GoodViewModel @Inject constructor(
private val userRepository: UserRepository
) : ViewModel() {
private val _users = MutableStateFlow<List<User>>(emptyList())
val users: StateFlow<List<User>> = _users.asStateFlow()
init {
loadUsers()
}
private fun loadUsers() {
viewModelScope.launch {
try {
_users.value = userRepository.getUsers()
} catch (e: Exception) {
// Handle error
}
}
}
}
Reference Documentation
Detailed material lives alongside this skill and is read on demand:
- Code Examples — Jetpack Compose App Structure, MVVM with ViewModel and StateFlow, Room Database, Retrofit API Service, Navigation with Compose, WorkManager Background Task
Resources
Documentation
Tools
Libraries
Testing
Community
1---2name: android-expert3description: Expert in Android development with Jetpack Compose, Material Design, ViewModel, and modern Android architecture. Use when the user mentions mobile, Kotlin, Jetpack Compose, Material Design, or Google, or when the task involves Android Architecture, Android Components, Jetpack Libraries, or Activity/Fragment Lifecycle.4---56# Android Expert78You are an expert in Android development, Jetpack Compose, Kotlin, Material Design, and modern Android architecture.910## Core Concepts1112### Android Architecture1314- **MVVM (Model-View-ViewModel)**: Recommended architecture pattern15- **MVI (Model-View-Intent)**: Unidirectional data flow16- **Clean Architecture**: Domain, data, presentation layers17- **Repository Pattern**: Data source abstraction18- **Use Cases/Interactors**: Business logic encapsulation19- **Dependency Injection**: Hilt/Dagger for DI2021### Android Components2223- **Activity**: Single screen with UI, entry point24- **Fragment**: Reusable UI portion within Activity25- **Service**: Background operations26- **BroadcastReceiver**: System-wide event notifications27- **ContentProvider**: Manage shared app data28- **Intent**: Messaging between components2930### Jetpack Compose3132- **Declarative UI**: Describe UI as functions of state33- **Composable Functions**: Building blocks of UI34- **State Management**: remember, mutableStateOf, StateFlow35- **Recomposition**: UI updates when state changes36- **Side Effects**: LaunchedEffect, DisposableEffect, SideEffect37- **Material Design 3**: Modern design system3839### Jetpack Libraries4041- **ViewModel**: UI-related data holder, lifecycle-aware42- **LiveData**: Observable data holder, lifecycle-aware43- **Room**: SQLite abstraction layer44- **Navigation**: Navigate between destinations45- **WorkManager**: Deferrable background work46- **DataStore**: Modern data storage (replaces SharedPreferences)47- **Paging**: Load data in pages4849### Activity/Fragment Lifecycle5051**Activity**: onCreate → onStart → onResume → onPause → onStop → onDestroy52**Fragment**: onAttach → onCreate → onCreateView → onViewCreated → onStart → onResume5354## Best Practices5556### Jetpack Compose5758- Keep composables small and focused59- Hoist state to make composables reusable60- Use `remember` for objects created during composition61- Use `derivedStateOf` for calculated values62- Avoid side effects in composition63- Use `LaunchedEffect` for one-time operations64- Leverage `collectAsState()` for Flow/StateFlow6566### Architecture6768- Follow MVVM or MVI pattern69- Separate concerns (UI, business logic, data)70- Use dependency injection (Hilt)71- Repository pattern for data sources72- Use sealed classes for state representation73- Prefer Kotlin Coroutines over callbacks74- Use StateFlow/SharedFlow over LiveData in new code7576### Performance7778- Use `LazyColumn`/`LazyRow` for lists79- Implement proper list keys in Compose80- Profile with Android Profiler81- Optimize database queries (indexes, pagination)82- Use WorkManager for background tasks83- Implement proper caching strategy84- Avoid memory leaks (lifecycle awareness)8586### Security8788- Use encrypted SharedPreferences89- Store sensitive data in Android Keystore90- Implement certificate pinning91- Validate all user input92- Use ProGuard/R8 for code obfuscation93- Follow security best practices94- Request minimum required permissions9596## Anti-Patterns9798### Common Mistakes99100- **Context leaks**: Don't hold Activity context in long-lived objects101- **Blocking main thread**: Use coroutines for I/O operations102- **Ignoring lifecycle**: Use lifecycle-aware components103- **Not handling configuration changes**: Use ViewModel104- **Memory leaks**: Clean up observers, callbacks105- **Hardcoded strings**: Use string resources106- **Not using dependency injection**: Tightly coupled code107- **Ignoring accessibility**: Support TalkBack, large text108109### Bad Code Example110111```kotlin112// DON'T: Blocking main thread, context leak113class BadViewModel(private val context: Context) : ViewModel() {114 fun loadData(): List<User> {115 // Blocking I/O on main thread116 val response = URL("https://api.com/users").readText()117 return JSONArray(response).toList()118 }119}120121// DO: Proper architecture with DI and coroutines122@HiltViewModel123class GoodViewModel @Inject constructor(124 private val userRepository: UserRepository125) : ViewModel() {126 private val _users = MutableStateFlow<List<User>>(emptyList())127 val users: StateFlow<List<User>> = _users.asStateFlow()128129 init {130 loadUsers()131 }132133 private fun loadUsers() {134 viewModelScope.launch {135 try {136 _users.value = userRepository.getUsers()137 } catch (e: Exception) {138 // Handle error139 }140 }141 }142}143```144145## Reference Documentation146147Detailed material lives alongside this skill and is read on demand:148149- [Code Examples](references/EXAMPLES.md) — Jetpack Compose App Structure, MVVM with ViewModel and StateFlow, Room Database, Retrofit API Service, Navigation with Compose, WorkManager Background Task150151## Resources152153### Documentation154155- [Android Developers](https://developer.android.com/)156- [Jetpack Compose](https://developer.android.com/jetpack/compose)157- [Kotlin Documentation](https://kotlinlang.org/docs/home.html)158- [Material Design 3](https://m3.material.io/)159160### Tools161162- [Android Studio](https://developer.android.com/studio)163- [Android Profiler](https://developer.android.com/studio/profile)164- [Layout Inspector](https://developer.android.com/studio/debug/layout-inspector)165- [Google Play Console](https://play.google.com/console/)166167### Libraries168169- [Jetpack Libraries](https://developer.android.com/jetpack)170- [Hilt](https://dagger.dev/hilt/) - Dependency injection171- [Retrofit](https://square.github.io/retrofit/) - HTTP client172- [OkHttp](https://square.github.io/okhttp/) - HTTP client173- [Moshi](https://github.com/square/moshi) - JSON library174- [Coil](https://coil-kt.github.io/coil/) - Image loading175- [Accompanist](https://google.github.io/accompanist/) - Compose utilities176177### Testing178179- [JUnit](https://junit.org/) - Unit testing180- [Mockito](https://site.mockito.org/) - Mocking framework181- [Espresso](https://developer.android.com/training/testing/espresso) - UI testing182- [Turbine](https://github.com/cashapp/turbine) - Flow testing183184### Community185186- [r/androiddev](https://reddit.com/r/androiddev)187- [Android Developers Blog](https://android-developers.googleblog.com/)188- [Kotlin Blog](https://blog.jetbrains.com/kotlin/)189- [Android Weekly](https://androidweekly.net/)