简体   繁体   中英

Implement Location Tracking in Android

I want to track the user location at every 1 minute and store user location in database. If the user location does not change for 30 min then i have to give the notification to user and if user does not close app at particular time. eg: 8.00 pm then also i have to give notification to user

The tracking should be in separate thread so that app can perform other task while location tracking is in progress.

I am totally stuck in this that how can i make separate thread for three things :

  1. for location tracking

  2. for 30 min reminder notification

  3. for 8.00 pm reminder

if the notification is shown to user and if the location changes then notification should be removed and tracking should be done normally

I see no need to use threading for this. The Android documentation on the location strategy page defines how to get updates on the location, and the Countdown timer can be used to do your timing.

Your battery life will suck if you check the location every minute.

Anyway, all of these tasks can be completed by using the AlarmManager . You'll set up a time for the next event and when it happens your code will run, even if your Activity is in the background. I'm not exactly sure what you mean by "close the app at 8 pm", the app doesn't need to be visible for these things to happen.

You need to use Service for this, and in service you can implement the location listener with with one minute interval, and for battery optimization you should you Google Location API . And you also use the Activity recognition for finding out the user movement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM