Office Hours — Today, February 11

Yesterday, February 10

Feb 11
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
Yaniv S.
has entered the room
Mark M.
hello, Yaniv!
how can I help you today?
Yaniv S.
Hi Mark
my problem is this
I have a service that runs on BOOT COMPLETED
and basically never destroyed
it listens for messages
what I want is for other applications to be able to use this service like a server
and bind to it, so when a message is received it is sent to other apps that bind to it
I coudn't find how to do that
how to send message from a service to other apps
every guide shows how to send a message from the client to the service
Mark M.
not every guide
for example, you are a subscriber to my book
and my book certainly covers other options
particularly in the "Remote Services and the Binding Pattern" chapter
starting on page 2471 in the PDF edition of Version 6.4 of the book
Yaniv S.
is there an example on how to do that?
Mark M.
well, first we need to determine what the right answer is for "that"
9:05 AM
Mark M.
you wrote: "so when a message is received it is sent to other apps that bind to it"
9:05 AM
Yaniv S.
I was thinking , 5 min ago , that maybe creating custom broadcast receiver is also an option
Mark M.
that is definitely an option
Yaniv S.
and my service will broadcast the message when it gets it
and other apps will pick it up,
Mark M.
as would be publishing a ContentProvider and having the clients register a ContentObserver to find out about changes
so, let me ask a couple of questions:
Yaniv S.
yes but content provider means i need to obtain the messages in some sort of database
and i dont want that
Mark M.
1. if a message arrives, what client apps need to find out about it? all of them regardless of whether they are running? or only those currently running?
Yaniv S.
i dont want to save the messages if no other app listens for it
umm.. not sure I understand
Mark M.
OK
let's suppose that your app is installed on a phone
and a message comes in
Yaniv S.
ok
Mark M.
there are 2,137 other applications, also installed on this phone, all of which *could* be interested in your message
however, only 6 of them are running right now
when the message comes in, how many apps should receive it: 6? 2,137? or something else?
Yaniv S.
which ever app is listening for this particular message
for this particular service
9:10 AM
Yaniv S.
If im creating my custom broadcast
only apps that listen for this specific broadcast will receive the msg , no
?
Mark M.
I am trying to understand how all of this is supposed to work at a logical level
are all of these apps (the one with the service and the ones listening for messages) yours?
Yaniv S.
yes
Mark M.
ah, OK, that helps
next: are you building your own hardware?
Yaniv S.
yes sorry for not being clear
Mark M.
or your own ROM mod?
Yaniv S.
no , I have an android based device that Im working on
Mark M.
and these apps will be pre-installed on that device?
or are these apps being publicly distributed, such as through the Play Store?
Yaniv S.
they will be pre installed , sort of
9:15 AM
Yaniv S.
meaning that each client will have his own device with his own applications installed on the device
Mark M.
can the client uninstall these apps? in particular, can the user remove the app that contains this message-collecting service?
Yaniv S.
there wont be play store on the devices
well , right now it can be deleted but the goal is that the message collecting service will stay installed and running and could not be removed
Mark M.
OK
in that case, having the central message collecting service is fine
Yaniv S.
lets say that this is a service that it's in the client's interest to delete
Mark M.
you mean, not to delete, right?
Yaniv S.
no i mean to delete .
we don't want clients to be able to delete that service is my point
Mark M.
OK, that is what I thought that you meant
next: how big are these messages? is a message something small (such as a bit of JSON) or something large (such as a photo)?
Yaniv S.
so , which options is better, a bound service or a broadcast
Mark M.
we are getting to that -- I need some more design information before I can give you a recommendation
Yaniv S.
the message is small , its basically a bundle of 2 int's and a string
Mark M.
OK, so that is something that most IPC can handle
9:20 AM
Mark M.
now, let's go back to a point I was trying to uncover earlier...
let's call your app with the message-collecting service S
so, S is installed on the device
and let's say that there are three other apps that are supposed to get messages from S, called A, B, and C
when S gets a message that A needs, if A is not running (has no process), what is supposed to happen?
does A need to be started up and handed the message?
does the message get queued somewhere for A to pick up later?
or is the message lost?
Yaniv S.
no, the message is lost and i dont care about it
only when A is running and requesting messages will the messages be received
Mark M.
in that case, a broadcast is probably not what you want
as the broadcast would cause A to start running if it was not already running
Yaniv S.
oh
Mark M.
and, since you do not need message persistence, the ContentProvider/ContentObserver approach (that you did not like) is not needed
and so, your original plan of the service binding is probably the right one
in the chapter on "Remote Services and the Binding Pattern", I have a sample showing how to pass data from the service back to the client
Yaniv S.
but is the client a different app?
Mark M.
in the sample, the client is asking the service to download a file, and the service sends back a success/failure indication
yes, they are separate apps
9:25 AM
Mark M.
for binding between apps, you need to use AIDL to describe the interface
normally, we think of this as being the service having a Binder based on that AIDL that is the implementation of the interface
and the client has a proxy that allows it to invoke methods on that interface, as if the service were a local object, when in reality is it in another process
however, given that you already have an established client->service binding, you can also use AIDL to send data from service to client
in this case, the *client* has the Binder, and the *service* gets the proxy
and that's what I cover in the book
Yaniv S.
so it sounds like exactly what I need.
Mark M.
particularly, you will want to read the "Servicing the Service" section, starting on page 2486 of the Version 6.4 PDF
Yaniv S.
are you sure thats the page num?
it jumps to JVM scripting
Mark M.
it is the page number as seen at the bottom of the page
Yaniv S.
oh ok
Mark M.
if your PDF viewer ignores my page numbering, try page 2535
Yaniv S.
page 2486 is "Traceview"
9:30 AM
Mark M.
are you looking at Version 6.4?
Yaniv S.
oh no! I have 6.2
oops
im not updated :(
Mark M.
the material is in there too, though I rewrote that chapter relatively recently
you're obviously a subscriber, so download Version 6.4 from the Warescription site when you get a chance
Yaniv S.
ok so just to be clear , I need to read Servicing the service and Remote Services and the Binding Pattern.
Mark M.
yes, where "Servicing the Service" is a section in the "Remote Services and the Binding Pattern" chapter
Yaniv S.
ok Mark, thank you for your help
Mark M.
you are very welcome
Yaniv S.
(Im staying here just because I want the transcript in front of me)
9:35 AM
Mark M.
also note that that chat transcript will be uploaded to http://commonsware.com/office-hours/ shortly after the chat ends
9:35 AM
Yaniv S.
thanks
Mark M.
and, if you have other questions, go right ahead -- it is a quiet chat room today
Yaniv S.
thats it for now , got some reading to do :)
Mark M.
OK
10:00 AM
Mark M.
that's a wrap for today's chat -- the next chat is tomorrow at 4pm US Eastern
have a pleasant day!
Yaniv S.
has left the room
Mark M.
turned off guest access

Yesterday, February 10

 

Office Hours

People in this transcript

  • Mark Murphy
  • Yaniv Sheinfeld