For a school project, i have to do an Android project (i am new to Android coding) where i must track the user location and record his travelled distance. For this, i use the Google Fused Location API.
I am having good results concerning the tracking, but it is only working when the app is in the foreground.
I have to continue to track the user location even when the phone is sleeping, and calculate his travelled distance.
I made some researches and found some solutions with AlarmManager
, or with the requestLocationUpdates
using PendingIntent
. But i can't figure out what is the best to use in my situation.
The "only" thing i want to do while the phone is sleeping is to continue getting his location and increment a float with his distance, so i can update the UI when the user is back on the app screen with his correct distance travelled.
What is the best way to do this in my case ?
Thank for your answers.