How to run GPS listener in background using service - Android
How to ru开发者_JAVA技巧n GPS listener in background using service. ?
you need to use the Handler for that which will use the listener and call on specific time like this way.
private Handler handler;
onCreate(){
handler = new Handler();
handler.post(gpsListenr);
}
here when the service was created at that time the gpslistener will be called.
Runnable gpsListener = new Runnable(){
public void run(){
// do something and then call again this listener by handler with delay time
handler.postDelay(gpsListener,1000); /// this will call gpslistener every 1 sec.
}
}
You can use a Service which always runs in the background..and in the background service you can get the current latitude and longitude and you can further convert these lats and longs into proper location using the Android geocoder class... check the follwing link
http://www.androidcompetencycenter.com/?s=GPS
精彩评论