I have an application that uses a service for some of its functions.
One of my calls to the service is called from onResume
and therefor I needed to make sure the service was connected before calling it.
I used the answer from this question is there a 'block until condition becomes true' function in java? to put a synchronized block just before calling the method from my service, with a syncObject.wait()
command, and to release it, I placed another synchronized block with syncObject.notifyAll()
in the onServiceConnected
method.
What happend is that after getting to the syncObject.wait()
call, the application just hung, waiting forever. Not only the the syncObject.notify()
was never reached, the onServiceConnected method was not even called.
Removing the synchronized block solved the issue, but that would mean that I'll have to put the call to the service method inside onServiceConnected()
, which is problematic in my case (there are conditions in onResume
that will determine if that part of the code should be executed or not)
Note: I do already have a solution for it, but it's sort of a workaround and I would really just like to put a line that blocks the code, until the service is connected.