Skip to main content

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:

PatternTestabilityComplexityView Responsibility
MVCLowLowHandles input and rendering
MVPHighMediumRendering only
MVVMHighMediumBinding 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:

  1. Local database (SQLite, Room, Core Data, Realm)
  2. Synchronization mechanism
  3. Network state monitoring
  4. Conflict resolution strategy

Data Flow:

  1. Read from local database (immediate response)
  2. Fetch from network in background
  3. Update local database
  4. UI observes local database changes

Conflict Resolution Strategies:

StrategyDescription
Last-write-winsMost recent change overwrites
Server-winsServer data takes precedence
Client-winsClient data takes precedence
Manual resolutionUser 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:

TierStorageCharacteristics
MemoryRAMFast access, limited size, cleared on app termination
DiskFile systemSlower 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:

TypeDefinition
Cold startApplication not in memory
Warm startApplication in background memory
Hot startApplication 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:

  1. Application registers with OS for push capability
  2. OS returns device token
  3. Application sends token to server
  4. Server sends notification to APNs (iOS) or FCM (Android)
  5. Platform delivers notification to device
  6. Application handles notification

Types:

TypeDescription
Alert/BannerUser-visible notification
Silent/DataBackground update without user notification
RichNotification 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)