I have implemented Bluetooth in several of my projects where the Android 
device is the user interface to a custom device with a Bluetooth module 
using the SPP profile (serial port replacement).  But I want to clean up my 
code and make it more robust.  Since I expect to be doing more of these 
projects in the future, I would like to modularize my Bluetooth Service so 
that it does not depend on the client class code in any way.  I've got a 
Service working, complete with a thread to read Bluetooth data and deliver 
each packet of data to the client (which is generally a local Activity).  
But my method of delivering data back to the client is by means of a 
handler in that client.  That means my Bluetooth Service code needs to 
depend on the client code.  I want to get away from this method for that 
reason.  The Binder interface  when the Activity binds to the client is 
fine for the client calling the Service.  But I can't find a similar 
lightweight method for the Service to communicate with the client (such as 
when it receives a packet of Bluetooth data).  My Bluetooth thread that 
reads the data can post to a handler to get on the UI thread.  But then I 
am stuck.  If I could create another Binder in the opposite direction, that 
would be great.  The client would just create the instance of Binder and my 
Service could call a method in that Binder without have to know anything 
more about the client class.  But how can I pass a Binder created in the 
client to the Service?  I don't think I can do it in the Intent passed in 
with bindService, because a Binder is not Parcelable, so it cannot be added 
to the Intent with putExtra.

I know that Messenger and AIDL exist, but I prefer the lightweight methods 
for performance reasons.  Is there something I am missing that seems to 
make this job so hard?

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to