Android background service problem
I've declared a background service from the android manifest, this service is to be started from within the main Activity of the application and run in an infinite loop to perform location updates to an external server.
This background service runs in a separate process than the process of the main activity of the application (using the android:process tag in the manifest declaration of the service). The issue I am having is that when requesting GPS location updates from within the service, then the LocationListener's onLocationChanged() method is never called, even when I send mock location using DDMS/geo command. But on the other hand, requesting GPS location updates from the main activity of the application does work and开发者_如何学编程 the onLocationChanged() method is being called properly when a fix is received, so I am wondering what is needed to be modified in order to get the same behaviour from within a service rather than an activity.
Thanks in advance for your help; Hass.
this service is to be started from within the main Activity of the application and run in an infinite loop to perform location updates to an external server.
Please don't do that, as you waste memory. Please use AlarmManager
to trigger a self-stopping Service
(like an IntentService
) periodically. And, since you appear to be getting locations, consider using my LocationPoller
service.
This background service runs in a separate process than the process of the main activity of the application (using the android:process tag in the manifest declaration of the service).
Please don't do that. You waste memory and add no value. It may also be contributing to your problems.
so I am wondering what is needed to be modified in order to get the same behaviour from within a service rather than an activity.
Getting locations within a service works just fine. See the LocationPoller
for an example of this in use.
精彩评论