Android, a quick question about binding to a service

Is there a way to find out if an action is associated with a service? Something like boolean isBoundToService(ServiceConnection sc)?

Sometimes, when I play with my application, I get an exception when it tries to untie a service that is not connected.

+3
source share
1 answer

I do not believe that there is a way that you can call to find out about it. However, what I usually saw was to keep a boolean in an activity that keeps track of whether the service is connected. You would set it to true in your callback ServiceConnection.onServiceConnected()and set it to false in ServiceConnection.onServiceDisconnected().

+6
source

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


All Articles