Urgent.News

What's breaking now, across thousands of outlets.

Tech

Architecting a Geofencing Engine that Avoids Battery Drain on Android

It was the middle of a Friday sermon. The mosque was silent, the air heavy with focus, until a high-pitched, upbeat ringtone tore through the stillness. It wasn't mine, but the collective wince from the hundred people around me was visceral. I watched the man frantically scramble to pull his phone from his pocket, his face bright red with embarrassment. It is a universal human experience: the…

In the midst of a Friday sermon, a high-pitched ringtone shattered the serene atmosphere. The man who inadvertently triggered the sound was visibly embarrassed. This experience led to the creation of Muffle, a solution aimed at eliminating the cognitive burden of remembering to adjust settings in a location-driven world. Existing options were either manual or excessive in battery consumption.

The key to a successful geofencing engine lies in using the GeofencingClient API provided by Android. This system handles location updates, only waking the app when the user crosses a defined boundary. The real challenge is managing the PendingIntent that triggers when entering or exiting the area. The GeofenceBroadcastReceiver should be kept lean to avoid blocking the main thread or causing an ANR.

The system operates at the system level, consuming minimal battery when the phone is stationary. An edge case that was encountered was the 'proximity' issue, where users oscillate between 'inside' and 'outside' states due to poor GPS signal. A debounce mechanism was implemented to prevent rapid-fire toggles. Another crucial aspect was handling the exit event reliably, especially when the app is killed or the phone is turned off.

The app must query the current location against active geofences and force a state sync if necessary. The user's battery statistics should be a primary focus during development. Common mistakes include holding wake locks for too long, leading to excessive battery drain. Developers should trust the system APIs and avoid polling logic, as Google has optimized location services for battery efficiency.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at dev.to →

More in Tech

From a phone app to a cluster

Originally published at eyosias.me . This is a chapter in the Ivyk8 series. TL;DR Ivyk8 is Ivy + k8s: a read-only desktop dashboard for the backups my phone app writes to Google Drive.

  • Ivy Wallet+ began as Android open-source money manager, archived by owner.
  • Author forked, added features, inspired desktop dashboard idea.
  • Project scaled down to 3 stateless TypeScript services, Kubernetes.

Building an offline snag-list app with Expo, Skia and pdf-lib

A snag list (a punch list in the US) is the walk-round at the end of a job: you photograph every defect, mark it up, note where it is, and send the builder one numbered report.

  • PunchSheet is an offline snag list app priced at $9.99
  • Uses Expo SQLite for data storage and React Native Skia for markup
  • Backup achieved through single .punchsheet file

More from Thursday 29 October →