Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Quick question on service binding

Tags:

java

android

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.

like image 458
user283494 Avatar asked Dec 07 '25 06:12

user283494


1 Answers

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().

like image 118
Erich Douglass Avatar answered Dec 08 '25 21:12

Erich Douglass



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!