I have done a lot of research on this, but still not sure if I can connect to an android service synchronously. startService() and bindService() service calls are asynchronous by nature and what I'm trying to do is make this behavior synchronous.
I tried writing startService(), bindService() and ServiceConnection object initialization (contains onServiceConnected() etc.) in a separate thread which is started from the main thread. And the main thread waits until onServiceConnected() is invoked on another thread and service object gets initialized, but since onServiceConnected() is only invoked by the main thread (http://developer.android.com/reference/android/content/ServiceConnection.html) which is blocked due to wait call, it forms a deadlock.
Does anyone know if my above reasoning is correct/incorrect? Is there another way to achieve the synchronous behavior? Or the only option is to invoke service functions after onServiceConnected() callback happens?
EDIT: (to explain it's not the exact duplicate of other question)
In the other question, the application connects with the service asynchronously and expect it to behave synchronously as it mentioned "By adding all kinds of Log.xx I found that the code after if(bindService(...)) actually goes BEFORE ServiceConnection.onServiceConnected is being called".
However, I'm already aware of this and the question is about if at all there is a way to connect with the service synchronously.