Android Development Best Practices
General Kotlin Guidelines
Basic Principles
- Use English for all code and documentation
- Always declare variable and function types explicitly
- Avoid the
any type; create necessary custom types
- Eliminate blank lines within function bodies
Naming Standards
- PascalCase: Classes, interfaces, enums
- camelCase: Variables, functions, methods
- underscores_case: Files and directories
- UPPERCASE: Environment variables, constants
- Avoid magic numbers; define constants instead
- Functions should start with action verbs
- Boolean variables use prefixes:
isLoading, hasError, canDelete
Function Design
- Keep functions under 20 instructions with single responsibility
- Use verb-based naming
- Prefix boolean returns with
is, has, or can
- Prefix void returns with
execute, save, send
- Combat nesting through early returns, utility extraction, and higher-order functions
- Use default parameters instead of null checks
- Consolidate parameters into objects (RO-RO pattern)
Data and Classes
- Employ data classes for data structures
- Encapsulate primitives in composite types; validate internally
- Favor immutability; use
val for unchanging values
- Follow SOLID principles; prefer composition over inheritance
- Keep classes under 200 instructions, 10 public methods, 10 properties
Exception Handling
- Reserve exceptions for unexpected errors
- Catch exceptions only to fix anticipated issues or add context
- Create custom exception types for domain errors
Android Architecture
Clean Architecture
- Implement clean architecture with clear layer separation
- Use repository pattern for data persistence and caching
- Keep business logic in Use Cases or Interactors
- Separate concerns between UI, domain, and data layers
Project Structure
app/
├── data/ # Data sources, repositories, models
├── domain/ # Use cases, domain models, interfaces
├── presentation/ # UI components, ViewModels, state
└── di/ # Dependency injection modules
MVI Pattern
- Deploy MVI pattern for state and event management
- ViewModels manage UI state as a single immutable state object
- UI components observe state and render accordingly
- Handle user intents/events through a single entry point
- Keep side effects predictable and traceable
UI Development
Navigation
- Use Navigation Component for fragment and activity routing
- Define navigation graph for app flow
- Handle deep links through Navigation Component
- Implement safe args for type-safe navigation arguments
Main Activity Structure
- MainActivity manages primary navigation
- Use BottomNavigationView for main destinations (Home, Profile, Settings, etc.)
- Handle navigation state properly across configuration changes
View Binding and State
- Use ViewBinding for type-safe view access
- Use Flow or LiveData for UI state management
- Observe state changes in lifecycle-aware manner
- Handle loading, error, and success states consistently
UI Framework Preferences
- Prefer XML layouts and Fragments over Jetpack Compose (unless Compose is specifically required)
- Use ConstraintLayout for complex layouts
- Apply Material 3 design guidelines
- Follow responsive design practices for different screen sizes
Authentication Flow
Structure authentication screens properly:
- Splash Screen - Initial app launch
- Login Screen - User authentication
- Register Screen - New user registration
- Forgot Password Screen - Password recovery
- Verify Email Screen - Email verification
Testing
Unit Testing
- Follow Arrange-Act-Assert conventions
- Test ViewModels, Use Cases, and Repositories
- Use test doubles for dependencies
- Achieve good coverage of business logic
UI Testing
- Implement widget testing for UI components
- Write integration tests for API modules
- Test navigation flows
- Use Espresso for instrumented tests
Best Practices
Lifecycle Management
- Handle lifecycle events properly
- Avoid memory leaks from improper lifecycle handling
- Use lifecycle-aware components
Background Processing
- Use Coroutines for async operations
- Handle cancellation properly
- Use WorkManager for deferrable background work
Dependency Injection
- Use Hilt or Dagger for dependency injection
- Scope dependencies appropriately
- Keep DI configuration organized
Performance
- Avoid work on the main thread
- Optimize RecyclerView with DiffUtil
- Use lazy loading for heavy resources
- Profile and optimize memory usage
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: android-development3description: Android development guidelines for Kotlin with clean architecture, MVI pattern, Material Design, and best practices for building robust mobile applications Use when this capability is needed.4---56# Android Development Best Practices78## General Kotlin Guidelines910### Basic Principles11- Use English for all code and documentation12- Always declare variable and function types explicitly13- Avoid the `any` type; create necessary custom types14- Eliminate blank lines within function bodies1516### Naming Standards17- **PascalCase**: Classes, interfaces, enums18- **camelCase**: Variables, functions, methods19- **underscores_case**: Files and directories20- **UPPERCASE**: Environment variables, constants21- Avoid magic numbers; define constants instead22- Functions should start with action verbs23- Boolean variables use prefixes: `isLoading`, `hasError`, `canDelete`2425### Function Design26- Keep functions under 20 instructions with single responsibility27- Use verb-based naming28- Prefix boolean returns with `is`, `has`, or `can`29- Prefix void returns with `execute`, `save`, `send`30- Combat nesting through early returns, utility extraction, and higher-order functions31- Use default parameters instead of null checks32- Consolidate parameters into objects (RO-RO pattern)3334### Data and Classes35- Employ data classes for data structures36- Encapsulate primitives in composite types; validate internally37- Favor immutability; use `val` for unchanging values38- Follow SOLID principles; prefer composition over inheritance39- Keep classes under 200 instructions, 10 public methods, 10 properties4041### Exception Handling42- Reserve exceptions for unexpected errors43- Catch exceptions only to fix anticipated issues or add context44- Create custom exception types for domain errors4546## Android Architecture4748### Clean Architecture49- Implement clean architecture with clear layer separation50- Use repository pattern for data persistence and caching51- Keep business logic in Use Cases or Interactors52- Separate concerns between UI, domain, and data layers5354### Project Structure55```56app/57├── data/ # Data sources, repositories, models58├── domain/ # Use cases, domain models, interfaces59├── presentation/ # UI components, ViewModels, state60└── di/ # Dependency injection modules61```6263### MVI Pattern64- Deploy MVI pattern for state and event management65- ViewModels manage UI state as a single immutable state object66- UI components observe state and render accordingly67- Handle user intents/events through a single entry point68- Keep side effects predictable and traceable6970## UI Development7172### Navigation73- Use Navigation Component for fragment and activity routing74- Define navigation graph for app flow75- Handle deep links through Navigation Component76- Implement safe args for type-safe navigation arguments7778### Main Activity Structure79- MainActivity manages primary navigation80- Use BottomNavigationView for main destinations (Home, Profile, Settings, etc.)81- Handle navigation state properly across configuration changes8283### View Binding and State84- Use ViewBinding for type-safe view access85- Use Flow or LiveData for UI state management86- Observe state changes in lifecycle-aware manner87- Handle loading, error, and success states consistently8889### UI Framework Preferences90- Prefer XML layouts and Fragments over Jetpack Compose (unless Compose is specifically required)91- Use ConstraintLayout for complex layouts92- Apply Material 3 design guidelines93- Follow responsive design practices for different screen sizes9495## Authentication Flow9697Structure authentication screens properly:981. Splash Screen - Initial app launch992. Login Screen - User authentication1003. Register Screen - New user registration1014. Forgot Password Screen - Password recovery1025. Verify Email Screen - Email verification103104## Testing105106### Unit Testing107- Follow Arrange-Act-Assert conventions108- Test ViewModels, Use Cases, and Repositories109- Use test doubles for dependencies110- Achieve good coverage of business logic111112### UI Testing113- Implement widget testing for UI components114- Write integration tests for API modules115- Test navigation flows116- Use Espresso for instrumented tests117118## Best Practices119120### Lifecycle Management121- Handle lifecycle events properly122- Avoid memory leaks from improper lifecycle handling123- Use lifecycle-aware components124125### Background Processing126- Use Coroutines for async operations127- Handle cancellation properly128- Use WorkManager for deferrable background work129130### Dependency Injection131- Use Hilt or Dagger for dependency injection132- Scope dependencies appropriately133- Keep DI configuration organized134135### Performance136- Avoid work on the main thread137- Optimize RecyclerView with DiffUtil138- Use lazy loading for heavy resources139- Profile and optimize memory usage140141---142> Converted and distributed by [TomeVault](https://tomevault.io/claim/mindrally) — claim your Tome and manage your conversions.143<!-- tomevault:4.0:skill_md:2026-04-11 -->