I am new to Android and I want to create an app that tracks the user location very frequently even the app is in background or killed. I have tested a lot of things like a foreground service but it is taking too much battery.
I want to track my user with Geofencing and the principle would be so :
I first takes the user location, I create a geofence around this location with TRIGGER_EXIT and a radius of 20meters, and each time TRIGGER_EXIT is trigger, I want to get the last known user location and create again a geofence around this location etc...
I started to implement this but I don't know how can I get the last known user location in a broadcast receiver and create a geofence in it.
I followed exactly the android tutorial on Geofence : https://developer.android.com/training/location/geofencing
public class GeofenceBroadcastReceiver extends BroadcastReceiver {
// ...
public void onReceive(Context context, Intent intent) {
//Here is where I want to get a location point and add a geofence around this point
}
}
Also, do you think my solution with geofence is a good choice to track my user?