Mobile Development Concepts
This guide covers cross-platform mobile development concepts that appear in interviews.
Architecture Patterns
MVC (Model-View-Controller)
MVC separates application logic into three components:
- Model: Data and business logic
- View: UI presentation
- Controller: Coordinates between model and view
On iOS, UIViewController often contains both controller and view logic, leading to large view controllers.
MVP (Model-View-Presenter)
MVP separates concerns more strictly:
- View: Passive, delegates user input to presenter
- Presenter: Contains presentation logic, updates view
- Model: Data and business logic
The view does not interact directly with the model. The presenter handles all logic and updates the view through an interface.
MVVM (Model-View-ViewModel)
MVVM uses data binding between view and view model:
- View: Observes view model, renders UI
- ViewModel: Exposes data and commands for the view
- Model: Data and business logic
The view binds to properties on the view model. When properties change, the view updates automatically. This pattern is used with SwiftUI, Jetpack Compose, and reactive frameworks.
Comparison:
| Pattern | Testability | Complexity | View Responsibility |
|---|---|---|---|
| MVC | Low | Low | Handles input and rendering |
| MVP | High | Medium | Rendering only |
| MVVM | High | Medium | Binding and rendering |
Dependency Injection
Dependency injection passes dependencies into objects rather than having objects create their own dependencies.
Without DI: A class creates its own dependencies internally, making testing difficult and coupling tight.
With DI: Dependencies are passed into the class through the constructor or other methods. The class does not create dependencies itself; they are provided externally.
Benefits:
- Testability: Mock dependencies in tests
- Flexibility: Swap implementations without modifying consumers
- Decoupling: Objects do not depend on concrete implementations
Tools:
- Android: Dagger, Hilt, Koin
- iOS: Swinject, Factory
Data and Networking
Offline-First Architecture
Offline-first applications function without network connectivity and synchronize when connectivity returns.
Components:
- Local database (SQLite, Room, Core Data, Realm)
- Synchronization mechanism
- Network state monitoring
- Conflict resolution strategy
Data Flow:
- Read from local database (immediate response)
- Fetch from network in background
- Update local database
- UI observes local database changes
Conflict Resolution Strategies:
| Strategy | Description |
|---|---|
| Last-write-wins | Most recent change overwrites |
| Server-wins | Server data takes precedence |
| Client-wins | Client data takes precedence |
| Manual resolution | User resolves conflicts |
API Error Handling
Error Categories:
- Network errors: No connectivity, timeout
- Server errors: 5xx status codes
- Client errors: 4xx status codes
- Parse errors: Invalid response format
Handling Strategies:
Use a Result type (sealed class or enum) with three cases: Success (containing the data), Error (containing message and optional error code), and Loading (indicating an in-progress request). This pattern enables type-safe error handling throughout the application.
- Retry with exponential backoff for transient errors
- Cache fallback for network failures
- User feedback with actionable error messages
- Logging for debugging
Image Caching
Image caching uses a two-tier approach:
| Tier | Storage | Characteristics |
|---|---|---|
| Memory | RAM | Fast access, limited size, cleared on app termination |
| Disk | File system | Slower access, larger capacity, persists across sessions |
Libraries:
- Android: Glide, Coil
- iOS: SDWebImage, Kingfisher
Considerations:
- Use URL as cache key
- Implement cache invalidation (version parameters in URLs)
- Set appropriate cache size limits
- Prefetch images for smooth scrolling
Data Security
Secure Storage:
- iOS: Keychain (encrypted, hardware-backed)
- Android: EncryptedSharedPreferences, Keystore
Network Security:
- HTTPS only
- Certificate pinning for sensitive applications
- Avoid logging sensitive data
Code Security:
- Obfuscation (ProGuard/R8 on Android)
- Root/jailbreak detection for high-security applications
- Avoid hardcoding secrets
Performance
App Startup Optimization
Startup Types:
| Type | Definition |
|---|---|
| Cold start | Application not in memory |
| Warm start | Application in background memory |
| Hot start | Application in foreground memory |
Optimization Strategies:
- Defer non-critical initialization
- Move heavy operations off main thread
- Reduce dependency count
- Use SplashScreen API (Android) or launch storyboard (iOS)
Memory Leak Prevention
Common Causes:
- Context/Activity references in long-lived objects
- Static view references
- Unregistered listeners and observers
- Inner classes holding implicit outer class references
Prevention:
- Use WeakReference for long-lived callbacks
- Unregister listeners in lifecycle methods
- Avoid static view references
- Use lifecycle-aware components
- Profile with LeakCanary (Android) or Instruments (iOS)
List Performance
Android RecyclerView:
- ViewHolder pattern for view reuse
- DiffUtil for efficient updates
setHasFixedSize(true)when size is constant- Shared RecycledViewPool for nested RecyclerViews
iOS UITableView/UICollectionView:
- Cell reuse with dequeue methods
- Prefetching data source
- Self-sizing cells with constraints
- Avoid complex layouts in cells
ANR Prevention (Android)
Application Not Responding occurs when the main thread is blocked for more than 5 seconds.
Prevention:
- Perform I/O operations on background threads
- Use coroutines or WorkManager for background work
- Keep main thread for UI operations only
- Use StrictMode during development to detect violations
iOS Watchdog: iOS terminates applications that block the main thread for approximately 20 seconds.
Battery Optimization
Primary Battery Consumers:
- GPS/Location services
- Network requests
- Screen/display
- CPU-intensive operations
Optimization Strategies:
- Batch network requests
- Use appropriate location accuracy
- Respect system power saving modes (Doze on Android)
- Minimize wake locks
- Use efficient animations with hardware acceleration
Platform Features
Jetpack Compose (Android)
Jetpack Compose is Android's declarative UI toolkit.
Concepts:
- Composable functions describe UI
- State hoisting lifts state to parent composables
- Recomposition updates only changed components
- Side effects use LaunchedEffect and DisposableEffect
SwiftUI (iOS)
SwiftUI is Apple's declarative UI framework.
Concepts:
- Views are structs (value types)
- State management via property wrappers (@State, @Binding, @ObservedObject)
- Automatic previews in Xcode
- Cross-platform support (iOS, macOS, watchOS, tvOS)
Push Notifications
Flow:
- Application registers with OS for push capability
- OS returns device token
- Application sends token to server
- Server sends notification to APNs (iOS) or FCM (Android)
- Platform delivers notification to device
- Application handles notification
Types:
| Type | Description |
|---|---|
| Alert/Banner | User-visible notification |
| Silent/Data | Background update without user notification |
| Rich | Notification with images or actions |
App Transport Security (iOS)
ATS enforces secure network connections on iOS.
Requirements:
- TLS 1.2 or later
- Forward secrecy
- Strong ciphers
Exceptions can be configured in Info.plist for specific domains, but HTTPS is required by default.
Screen Size Adaptation
Android:
- Use ConstraintLayout for flexible layouts
- Density-independent pixels (dp)
- Resource qualifiers for different screen sizes
- Foldable device APIs
iOS:
- Auto Layout with constraints
- Size classes (compact/regular)
- Safe area insets
- SwiftUI adaptive layouts
General Principles:
- Design for smallest supported screen first
- Test on multiple device sizes
- Use responsive patterns (collapsible navigation, adaptive grids)