Is it better to register for Location updates in Service or in Activity for Android? -


In one of the applications I am developing, I am registering for location updates in service. Is there a better way to do this? The application logic is that the service will remain active till application.

I have to face the problem at any time, say that the service was running once and the location update was working properly. But after approximately 4-5 hours, location updates automatically stop, so it makes me believe that after the time the system has passed, the system has been automatically shut down by the system. Please correct me if I am wrong here.

In this case, I have to register with the service instead of the service listener. Can anyone tell me whether I am understanding it correctly or not?

but approximately 4-5 hours of location updates automatically stop, so It believes me that after some time the system is automatically shut down by the system.

This is needed by onStartCommand () / code, it should keep your service around until it clearly is closed ( Ensure that your users know that this continuous running service can cause a drain on the battery, depending on your service

In this case, instead of service I Location listener must register with the activity.

When a listener references The listener of the activity will only work correctly, while the user's focus is to see (activity). When your activity is stopped or killed, you also have to hear; A remote service is a better option. .

Comments