jjNford
jjNford

Reputation: 5270

onBind and Service connect?

There seems to be a small delay after I bind to a remote service. The onServiceConnection works fine. The binding work fine. There is just a delay problem I think. For example in the onCreate() method of my activity if for instance say:

If I run this I get an error that says that no connection yet exists. However if I put the mRemoteServiceStub.doThis() in a method to a onClickListener it work perfect. So either the connection is not made until the activities onCreate has finished running or there is a delay on the connection being made.

Does anybody know ?

And is there way to delay the application from running until the connection is made this way I can use the connection right away with no trigger. (My implementation is correct)

Upvotes: 0

Views: 2881

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007534

If I run this I get an error that says that no connection yet exists.

bindService() is not synchronous. You cannot use your stub until onServiceConnected() is called on your ServiceConnection object and you create the client-side proxy from the IBinder.

And is there way to delay the application from running until the connection is made this way I can use the connection right away with no trigger.

Put your binder-dependent logic in onServiceConnected().

Upvotes: 2

Related Questions