Wednesday, July 13, 2011

[android-developers] Re: Accessing local data in a bound service

Thanks, Mark.

My onServiceConnected() code looks like this:

public void onServiceConnected(ComponentName className, IBinder
service) {

Log.i("INFO", "Service bound ");
mBoundService = ((MainService.LocalBinder)service).getService();

}

I'm assuming that the binder is mBoundService, which is of type
MainService. Once I do this, I'm not sure how to pass TRIP_INFO to it.
My knowledge of binders is slim.

Thanks,

/Ab

On Jul 12, 5:01 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> On Tue, Jul 12, 2011 at 7:54 PM, Ab Caballero <a...@mac.com> wrote:
> > What i wanted to do then was pass data to the service (one parameter)
> > by using putExtra() but i couldn't figure out how to get it to work.
> > Is it possible to use putExtra() while binding to a running service?
>
> To a running service, no. onBind() is only called once per distinct
> Intent, and you do not want to bind multiple times from the same
> activity, anyway.
>
> However, bear in mind that the primary -- perhaps complete -- reason
> you are binding is to get a Binder. You can supply TRIP_INFO via a
> method call on the Binder in onServiceConnected(). Passing data via
> extras is used when you are using startService() to send commands,
> rather than binding.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, One Low Price!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment