开发者

onBind and Service connect?

开发者 https://www.devze.com 2023-04-08 21:56 出处:网络
There seems to be a small delay after I bind to a remote se开发者_运维知识库rvice.The onServiceConnection works fine.The binding work fine.There is just a delay problem I think.For example in the onCr

There seems to be a small delay after I bind to a remote se开发者_运维知识库rvice. 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:

  • Note the mConnection onServiceConnect() sets mRemoteServiceStub correctly.

    bindService(mIntent, mConnection, Context.BIND_AUTO_CREATE); mRemoteServiceStub.doThis();

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)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号