accessing remote services functions
i ran into a problem with remote services. after i started and bound my service, i want/need to access it's functionality. this works just fine if i work with buttons and onclick-controllers just as in http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/RemoteServiceBinding.html
but actually, i need to access the services functions DIRECTLY after binding the service, like:
Intent intent = new Intent(IwlService.class.getName()); bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
String.valueOf(wlService.getDataFromService()); // this will CRASH the app!!!
if i access the service function "getDataFromService()" in an onClickListener, it works perfectly.
how do i access the services functions d开发者_开发技巧irectly after binding/starting the service?
but actually, i need to access the services functions DIRECTLY after binding the service, like:
That is not possible. The service may need to start up, for example. In the case of a remote service, that will take a few hundred milliseconds.
how do i access the services functions directly after binding/starting the service?
You don't. You rewrite your code to access your service starting with the onServiceConnected()
method in your ServiceConnection
object. Any time before that and your service is not ready.
精彩评论