Yes, there are a number of options: (1) In your activity use registerReceiver() for your own custom action (scoped to your package), and broadcast to that from the service. We aware that this opens you up to -any- application broadcasting to you through it unless you also define and require a signature-based permission.
(2) Create a PendingIntent to send results back to your activity and give it to the service. The service should be able to use to to send you data that you receive in onActivityResult(). Note that each time the result is delivered your activity will go through onPause() and onResume(). (3) Create a Handler in your activity, create a Messenger pointing to it, and give the Messenger to the service. The service can then just deliver whatever messages it wants back to the activity. (4) Easiest way: if your service and activity is running in the same process (I would expect this to be the common case), then follow the local service API demo where you can just directly call each other. Or have a global pointing to your activity while it is running that the service looks at, etc. For most app developers, I strong encourage that they have their service run in the same process as their activities, take advantage of that by using globals and direct calls between them, and end up with a much simpler situation to deal with and a much lighter-weight application (by avoiding having multiple processes running at the same time). On Fri, Dec 19, 2008 at 11:49 AM, Noonien Soong <nooniensoong2...@gmail.com>wrote: > > I got a question related to this. > > > I have an activity and a service. Right now they communicate via 2 > connections with 2 binders like this: > Activity binds to Service > Service sets up callback binding to Activity > Activity calls remote function in service over AIDL-thing ... ... > Service loads current data from sqlite DB. > Service starts thread and does some work. > Service saves the new state into the sqlite DB. > Work-Thread on Service is done. > now : Service sends a notice back to the Activity telling the activity > the operation has completed. > This is either done by a callback if the Activity is still up or with > the Notification-functionality ( the little icon thing on top of the > screen ), if the activity is down. > ( note: when the activity goes down, the service learns of that fact. > so when the work-thread is done, I know about the state of the > Activity ). > > now my question: Since the communication between my service and my > activity ( in either direction) is pretty simple ( just function > calls, no other data submitted), I was wondering if I could do the > thing simply by sending intents back and forth. I know how to send > intents from the Activity to the Service ( startService() ), but how > do I send intends the other way? > With sendBroadcast(Intent intent) from the Context - class? > I feel like if I could just send Intents back and forth it would make > things easier.. > > Or am I under a wrong impression here? > > Any comments appreciated! > > > > > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ 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-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---