I am currently using FusedLocationProviderClient
for requesting location updates in MainActivity
in onCreate
method. After activity gets created, a BroadcastReceiver
registered as location updates listener. But location updates still continues at night since I don't remove location updates from receiver, but I don't need updates at night since they are generally at home. I want to remove updates from receiver at 10PM and restart receiving location updates at 6AM everyday. I thought that AlarmManager
would be sufficient but I couldn't find a proper way to handle this problem. I could just ignore updates coming at night in receiver but I don't think that would be a battery efficient solution.
Summary
- Request location updates when user opens application first time and handle updates in background with BroadcastReceiver (
requestLocationUpdates(...)
) - Remove location updates from BroadcastReceiver at 10PM everyday since application doesn't need location updates at night (
removeLocationUpdates(...)
) - Request location updates at 6AM everydat since application needs location updates during day at background with BroadcastReceiver