It appears from all the code examples that we only want to invoke #unbindService (on the same context), if we have invoked #bindService, which is accomplished via a boolean check.
But there are no similar checks in the #bindService call -- i.e. we do not check if we have already bound first to avoid "double binding".
So my questions --
- "will bad things happen" if I bind a service multiple times but only unbind once, or it's only bad if i bind once and unbind multiple times? Such asymmetry seems weird to me but wanted to see if anyone knows the answer. I am playing with it now myself trying to figure it out but would prefer an "official" answer from more experienced devs.
- What is considered a "bind" and "unbound" operation -- is it the fact that i have simply invoked the #bind (or #unbind) API, and those calls must be paired, OR is the bound/unbound state indicated by the #onServiceConnected/Disconnected callback that must be paired? Google's own examples seem to indicate the former is true, could anyone confirm? If former is true, then a final more subtle question: if #bindService returns false, i.e. android won't even attempt to connect as it couldn't resolve the service, in that case is it safe to invoke #unbindService?
Thank you.