Nap Alarm Technical Deep Dive
Nap Alarm is a location-based transit alarm that allows commuters to sleep peacefully without missing their stop. Built natively for Android using Kotlin, it heavily leverages foreground services, geofencing APIs, and custom UI components to deliver a reliable experience.
Architecture & Core Technologies
- Language: Kotlin (100%)
- Architecture: MVVM (Model-View-ViewModel) with Clean Architecture principles
- Dependency Injection: Hilt
- Local Storage: Room Database for caching custom routes and settings
- Background Processing: Foreground Services & WorkManager for continuous GPS tracking
- Maps & Location: Google Maps SDK & Google Location Services API
Technical Challenges Overcome
1. Battery Drain Optimization
Continuous GPS polling is notorious for draining batteries. To solve this, Nap Alarm dynamically adjusts its polling frequency based on the user's distance from the destination. When far away, it polls less frequently; as the user approaches the geofence, polling increases to ensure an accurate trigger.
2. Reliable Background Execution
Modern Android versions aggressively kill background apps. By implementing a sticky Foreground Service with an ongoing notification, the app guarantees that the alarm will trigger even if the user swipes it away from recents.
Nap AlarmLocation-Based Transit Alarm
The Engineering Challenge
Standard mobile alarms are time-based, rendering them useless during transit delays. To solve this, Nap Alarm continuously tracks GPS boundaries.
We engineered custom native background services to bypass aggressive Android OS Doze restriction loops and designed a speed-sensitive telemetry manager that scales GPS queries down during high-speed segments, conserving battery.
The Security Angle: Anti-Theft Shield
Sleeping in public transits poses security risks. Nap Alarm integrates a hardware sensor fusion engine. When the "Anti-Theft Shield" is enabled, accelerometer variance triggers an instant high-decibel alarm block if the device is shifted or snatched.
Smart ETA Tracking
Adapts to live transit delays. Recalculates arrival boundaries dynamically to ensure accurate alert triggers.
Distance-Based Alarms
Uses pure distance triggers (e.g., wake up exactly 2 km away) for predictable arrivals independent of speed.
Smart Audio Routing
Intelligently routes alerts through earphones if plugged in, or speaker if unplugged, avoiding public disruptions.
Battery Optimized
Syncs GPS polling intervals dynamically with travel speed, dropping power consumption by up to 70% during long segments.
Route active
Monitoring Bounds
LAT: 12.9716 // LON: 77.5946