0

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.

Whin3
  • 675
  • 2
  • 9
  • 27
  • search for backgrond service for location updates. This will be a background service which will be keep running in background and listen the location updates at regular interval and then you can save it or update it in your storage. – Nikunj Sakhrelia Dec 15 '15 at 16:31
  • Should i have "two" location updaters to do that ? The one i use already for the foreground use and the second for background (and disable the foreground one while i am in background state) or only use the service for both ? – Whin3 Dec 15 '15 at 17:58
  • 1
    Yes, you can have multiple location updaters as per requirements, but if background service gives you result no need to have multiple one as both will have same result. – Nikunj Sakhrelia Dec 16 '15 at 11:12

0 Answers0