Ashish Agrawal
Ashish Agrawal

Reputation: 1977

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. e.g: 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

Upvotes: 0

Views: 541

Answers (3)

Kapil Vats
Kapil Vats

Reputation: 5515

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.

Upvotes: 0

Dobbo
Dobbo

Reputation: 1188

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.

Upvotes: 1

dmon
dmon

Reputation: 30168

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.

Upvotes: 0

Related Questions