androidkotlinandroid-geofence

Execute Broadcast Receiver onReceive code from the background


I'm working on an app with GEOfencing API. I have created a geofence and whenever a user leaves already specified geofence, broadcast receiver is triggered and I can successfully display a log message. However when my application is in the background, onReceive method of Broadcast Receiver is not triggered, even though Geofencing is working, my onReceive method will be triggered only when I open the app in foreground. How can this be achieved in the background?


Solution

  • I figured it out. The problem with was with Android Emulator. I didn't receive a Log message from my Broadcast receiver when I triggered the geofence (When my app was in background), because there is a BUG in Android Emulator. You need to have Google Maps Application opened to receive a trigger from geofence from your app in the background.

    It's a strange bug, and it took me few days of debugging to figure it out.