user283494
user283494

Reputation: 1907

Android, Quick question on service binding

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

Sometimes when I play around with my app I get an exception when it tries to unbind a service which is not bound.

Upvotes: 3

Views: 255

Answers (1)

Erich Douglass
Erich Douglass

Reputation: 52002

I don't believe there's a method you can call to find this out. However, what I've commonly seen done is to keep a boolean in the activity that tracks whether or not the service is bound. You'd set it to true in your ServiceConnection.onServiceConnected() callback and set it to false in ServiceConnection.onServiceDisconnected().

Upvotes: 6

Related Questions