1

I tried making my first geofencing app following google's tutorial and this tutorial http://www.coderzheaven.com/2016/06/20/geofencing-in-android-a-simple-example/ It works great when the app is open, but when I close the app I get no notification. So I tried running just the tutorial code and it had the same problem. However I noticed that when my app was running(which implemets geofencing the same way) and the tutorial was closed the tutorial's service worked becuase I got the notification from the tutorial.(Same thing if the tutorial was open and my app closed) What is wrong with the tutorial code?

kacsagit
  • 45
  • 1
  • 7

1 Answers1

3

Intent service used in the mentioned example works good if your app is in foreground but when the app is in background, this IntentService is never called.So we need to use Broadcast-Receiver instead of Intent service.

I found this blog helpful in getting solution.

http://davehiren.blogspot.in/2015/01/android-geofence-stop-getting.html

Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42
  • Thank you. I also found that the problem was that the geofence is not listening to location changes in the bacground, so I solved it with a location listener service. But your solution sounds better, so I will try it out. – kacsagit Apr 07 '17 at 12:54
  • Your welcome @kacsagit, It would be grateful if you could also share your solution here. – Akash Bisariya Apr 07 '17 at 13:08
  • Please see my [answer to a related post](https://stackoverflow.com/a/50864092/766755) that doesn't specifically solve this but should provide more background information. – Michael Krause Jun 14 '18 at 22:20