In my application uses current location lat,long. which is periodically update in every 5min. and run in background,means when i launch my application a pop up comes and ask for "do you want to use current locatio开发者_C百科n" if i press "yes" then service will be run on background of application and use current location lat long,means refreshing in every 5 min,so how to do it.How to make such service.
Please explain in detail as i am new in android . every help would be appreciated thanks in advance
Handling location updates in user-friendly and power-efficient way is no trivial task.
I highly recommend you read Reto Meier's A Deep Dive Into Location
(and the second part).
Update
There is a simple (and wrong) way to do it: set AlarmManager to wake your service every 5 min which requests the location.
This is wrong for several reasons. To do it right first answer yourself this questions:
- Do you need location updates exactly every 5 minutes?
- Even if your app is not active?
- Even if phone is in sleep mode?
- Even if phone is not moving for longer period (e.g. user is sleeping)?
- What accuracy do you need? 10m or 300m?
- Do you need GPS accuracy on all locations? GPS drains battery in matter of hours.
- Do you need updates if user is moving fast? 5 min in a car can mean 10 miles easily.
精彩评论