问题
Possible Duplicate:
requestLocationUpdates throws exception
I'm trying to create a service that when the server ask me, send my location. but can not find the way to do it, since everything is a background service. and I do not need to have UI interface. when I call requestUpdate () throws me an error and stops the application
locManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 15000, 0, locationListener);
runException Can't create handler inside thread that has not called Looper.prepare()
How I can run something to update the position from my service? anyone have any example or something to help me? I have not much experience yet.
回答1:
Well, its famous problem, See response in your Exception:
 ... that has not called Looper.prepare()
You need provide application's main looper.
Here is valid implementation:
mLocationManager.requestLocationUpdates(
                                        LocationManager.GPS_PROVIDER,
                                        15000,
                                        0,
                                        locationListener,
                                        Looper.getMainLooper()
                                        );
    来源:https://stackoverflow.com/questions/13826399/gps-location-on-service-android