A way of sending objects to/from service?

Put your problem here if it does not fit any of the other categories.

A way of sending objects to/from service?

Postby DRJTower » Thu Mar 18, 2010 6:51 am

I am new to android and trying to figure out how to communicate between activitys and services is making my head spin :(

Its my understanding that services run on an entirely different VM (which probably explains why communication is so different)

Is there any way to send objects (standard objects, and ones I create) from the activity to/from the service?
or
Does all data have to passed by Strings, ints, ect.. (Please say no /fingers crossed)

Does anyone have a link to a good guide/tutorial for this?

Thanks much for your help!
DRJTower
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 18, 2010 6:35 am

Top

Postby Christoph » Thu Mar 18, 2010 11:23 pm

User avatar
Christoph
Developer
Developer
 
Posts: 28
Joined: Thu Jul 02, 2009 3:34 am
Location: Bonn, Germany

Postby DRJTower » Fri Mar 19, 2010 5:14 am

Thanks for your reply Christoph, but I was hoping for guide or tutorial on this.

I did, however find that you can send objects to/from activities to/from services
IF they are serializable ( see Intent.putExtra(String, Serializable) and Bundle.getSerializable(key) )

However whenever I try to do this with my own objects I get casting errors.

I give Intent.putExtra(String, Serializable) my object of some class
Bundle.getSerializable(key) works (or at least it does not return null)

BUT
when I try to cast the object back to my class I get casting errors
and the object is not an instance of my class

I have user serialization before with files and sockets, and never had this problem.

Has anyone tried using this?
DRJTower
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 18, 2010 6:35 am

Re: A way of sending objects to/from service?

Postby pskink » Fri Mar 19, 2010 8:30 am

DRJTower wrote:Is there any way to send objects (standard objects, and ones I create) from the activity to/from the service?
or
Does all data have to passed by Strings, ints, ect.. (Please say no /fingers crossed)

Does anyone have a link to a good guide/tutorial for this?

Thanks much for your help!


http://developer.android.com/intl/de/gu ... /aidl.html

look for Parcelable
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests