MarLogic is a logistics and supply chain management application designed to track the transport of high-value or sensitive cargo (such as pharmaceuticals and perishable goods).
When a driver starts a delivery trip, the application must run a foreground service (FOREGROUND_SERVICE_LOCATION) to retrieve location updates for the following critical tasks:
1. GEOFENCING AND AUTOMATED HANDOVERS:
The app calculates distance thresholds in real-time. As soon as the driver enters a 200-meter radius around the destination, the geofencing feature automatically triggers the arrival event, updates the shipment status to "arrived" on the server, and records the handover.
2. COLD CHAIN SAFETY (BLE SENSORS):
During transit, the app connects to temperature and humidity sensors via Bluetooth Low Energy (BLE). It must associate every temperature log with the shipment's exact GPS coordinates in real-time to maintain a verified custody log.
WHY THIS TASK CANNOT BE PAUSED OR DEFERRED:
- If the operating system suspends or pauses the app in the background (which typically happens without a foreground service), the driver could pass through the 200-meter geofenced delivery zone without the app detecting the entry, breaking the automated delivery workflow and leading to incorrect status records.
- In the event of a cold chain breach (e.g., temperature exceeding safe thresholds), the alert must be generated immediately. A delay of even a few minutes caused by OS-deferred background tasks (e.g., WorkManager) could result in the complete spoilage of sensitive medical or food cargo.
USER CONTROL AND TRANSPARENCY:
Tracking is initiated only through the explicit action of the driver starting the trip. Throughout the journey, a persistent and visible notification is displayed in the system status bar: "Active delivery tracking - MarLogic is updating your location in the background," ensuring full transparency. The service terminates immediately when the trip is completed or cancelled by the driver.