Thanks, Mark.
Let me rewind because i tried something like that and didn't get very
far. What i would really like is for my service to access data from my
activity. But since i couldn't get that to work i thought i could do
the reverse and just deal with the fact that i was going to have two
files to deal with instead of one.
What I initially did was bind the service as below, which works:
void doBindService() {
bindService(new
Intent(com.drayagerecorder.TripInformationActivity.this,
MainService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
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?
The code I added but that didn't work was:
dataIntent = new Intent();
dataIntent.putExtra("trip information", TRIP_INFO);
Any help is appreciated and I hope that i wasn't too confusing.
/Ab
On Jul 12, 4:13 pm, Mark Murphy <[email protected]> wrote:
> On Tue, Jul 12, 2011 at 6:59 PM, Ab Caballero <[email protected]> wrote:
> > I am binding to a service to access GPS data. However I can't access
> > the data directly because it is local to the LocationListener class. I
> > have attempted to create a shared preference and access it that way:
>
> > SharedPreferences prefs =
> > getSharedPreferences(USER_SHARED_PREFERENCES, MODE_WORLD_READABLE);
> > Editor editor = prefs.edit();
> > long latitude = Math.round(loc.getLatitude());
> > long longitude = Math.round(loc.getLongitude());
> > editor.putLong(USER_LATITUDE, latitude).commit();
> > editor.putLong(USER_LONGITUDE, longitude).commit();
>
> > but the activity seems not to be able to access it and the
> > documentation seems to indicate that shared preferences can only be
> > used with activities. Is there a way for me to access this data once
> > the service is bound?
>
> Call a method on the Binder exposed by the service. That's the only
> reason you bound to it in the first place -- otherwise, you probably
> should not be using the binding pattern.
>
> --
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en