Retrieving data from Unbound Service on Android

I currently have an unrelated service that constantly captures my gps position, which I start at boot. Then I have an application that is supposed to draw where I was, pulling data from the service.

I cannot bind the service to talk to her, or it will be destroyed after the application is closed.

Is there any good way to retrieve data from an unrelated service or to keep a related service after I untie it?

Hooray!:)

+4
source share
2 answers

There is a way around your service. Call your service by calling startService, and then bind it to the service. In this way, your activities support the service life cycle.

+2
source

As the documentation says:

The service can be launched and related. In this case, the system will support maintenance while it is running or there is one or more connections

So, first start the startService () service , then bind it to onResume () and untie it to onPause (). However, the service will continue to work because it is running. And when you want to stop the service, either call stopSelf () from the service or stopService () from the activity. He will stop immediately, as soon as you untie him, if there is a living connection.

+2
source

Source: https://habr.com/ru/post/1347272/


All Articles