Apr 30 | 8:50 AM |
Mark M. | has entered the room |
Apr 30 | 8:55 AM |
Mark M. | turned on guest access |
Yaniv S. | has entered the room |
Mark M. |
hello, Yaniv!
|
Mark M. |
how can I help you today>
|
Yaniv S. |
hello
|
Mark M. |
er, today?
|
Yaniv S. |
I talked to you some time ago about binding an app to a service
|
Yaniv S. |
sort of like the "Servicing the service" example in your book
|
Yaniv S. |
reminder:
|
Yaniv S. |
I have a service that receives messages occasionally
|
Yaniv S. |
and when a message is received I want the app to receive it
|
Apr 30 | 9:00 AM |
Mark M. |
IIRC, you had several apps
|
Yaniv S. |
anyway Im using aidl and everything seems to be correct except that in the app
|
Yaniv S. |
the onServiceConnected is never called
|
Yaniv S. |
even though my onBind returns true
|
Yaniv S. |
so the binding isn't really happening
|
Yaniv S. |
View paste
(43 more lines)
|
Yaniv S. |
this is the "app"
|
Mark M. |
well, you are calling super.onResume() in onCreate(), which is unlikely to turn out well :-)
|
Yaniv S. |
its not really an app just some activity i want to test this IPC
|
Yaniv S. |
oh, oops.I didnt notice it. however I dont get any exception here
|
Mark M. |
beyond that, are there any interesting messages in LogCat?
|
Mark M. |
and, is onBind() being called?
|
Yaniv S. |
yes it is called and returns true
|
Mark M. |
onBind() cannot return true
|
Mark M. |
onBind() is a method in your service
|
Mark M. |
it returns a Binder
|
Yaniv S. |
oh I thought you meant bindService()
|
Yaniv S. |
no , onBind() is not called either
|
Yaniv S. |
View paste
(7 more lines)
|
Yaniv S. |
this is my onBind
|
Yaniv S. |
and these are my AIDL files, very simple :
|
Yaniv S. |
View paste
|
Yaniv S. |
View paste
|
Apr 30 | 9:05 AM |
Mark M. |
can you paste in your <service> element for this service from your manifest?
|
Yaniv S. |
View paste
|
Mark M. |
hmmmm, OK, that seems fine
|
Mark M. |
do any messages show up in LogCat when you try doing this binding?
|
Mark M. |
sometimes, problems in background stuff like this wind up with warning severity, rather than error, for some reason
|
Yaniv S. |
I honestly dont see any special messages
|
Mark M. |
is onCreate() on your service being called?
|
Yaniv S. |
yes , my service is working great in the background doing what it should be doing
|
Apr 30 | 9:10 AM |
Mark M. |
well, other than the super.onResume(), I do not see any other problems in what you have
|
Yaniv S. |
Its weird because I have another app that binds to the service and it does work. just not full IPC , just sends the service a message
|
Mark M. |
I honestly have not played with multiple apps binding to a service, but AFAIK, there is nothing you need to do special for that case
|
Mark M. |
though I would make sure that your Binder object's public API is nicely asynchronous, so you release the binder thread it is called on in a timely fashion
|
Mark M. |
you might also try starting from a clean slate (e.g., rebooting), then trying to use the app that is giving you problems *first*, before the working client
|
Yaniv S. |
how do you mean?
|
Mark M. |
if you look at my binding samples in the book, I fork a DownloadThread from the download() method on my Binder
|
Mark M. |
now, technically, I don't have to do that, as download() is not going to be called on the main application thread
|
Mark M. |
so I won't get an ANR or anything if I just do the download on the thread that I am called upon
|
Mark M. |
however, we do not control the pool of "binder threads" used for IPC
|
Mark M. |
and I have no idea if that pool grows
|
Mark M. |
so, your Binder objects' methods should return quickly, to return the binder thread to the binder thread pool
|
Mark M. |
which means if the Binder object wants to do more significant work (e.g., download a PDF), it should do so on its own separate background thread
|
Apr 30 | 9:15 AM |
Mark M. |
IOW, while the binder threads are not the main application thread, I recommend that you treat them as such, and spend as little time on them as possible
|
Yaniv S. |
I have no binder thread here
|
Mark M. |
yes, you do
|
Mark M. |
all Intent-based IPC winds up using binder threads
|
Mark M. |
you do not *explicitly* put stuff on that thread
|
Yaniv S. |
oh ok
|
Mark M. |
but, going back to my sample apps, my download() method will be called on a binder thread
|
Mark M. |
at least in the remote-service, AIDL scenarios
|
Mark M. |
(local services, it will be called on whatever thread calls the method)
|
Yaniv S. |
just like my getMessage method
|
Mark M. |
getMessage() and onMessageReceived() will be called on binder threads, yes
|
Yaniv S. |
but where should I look for my problem
|
Yaniv S. |
the client or the service?
|
Mark M. |
I suggested earlier in the chat that you restart your test device, then try running the client that is giving you problems first, before running the client that is working
|
Yaniv S. |
I am not even running the working client
|
Mark M. |
if the client now works, then your problem is more that the *second* app cannot bind, and the problem would seem to be more on the service side
|
Yaniv S. |
the working client only binds when I click a button in it's activity
|
Apr 30 | 9:20 AM |
Yaniv S. |
the not working one should bind as I run the activity
|
Mark M. |
that's fine, but if it is still the same service process, perhaps something about doing that work in the working client is triggering the problem in the not-working client
|
Yaniv S. |
so basically the working one is not really "colliding"
|
Mark M. |
which is why I would recommend a clean test, to ensure that the working one is not part of the picture
|
Mark M. |
I would even consider uninstalling the working client, to ensure it's not part of the mix
|
Yaniv S. |
ok, I'll try that
|
Mark M. |
if the problem recurs with solely the not-working client and the service, my guess is that the problem is on the client side, somehow
|
Mark M. |
if the problem goes away, then that suggests that whoever tries using the service *second* has a problem, and that would suggest that the problem is on the service's side
|
Yaniv S. |
and if the problem does go away how do I fix that in my service?
|
Mark M. |
beats me
|
Yaniv S. |
:)
|
Mark M. |
sorry, but I am pretty much out of ideas right now
|
Mark M. |
there's the super.onResume()
|
Yaniv S. |
basically more than one app can bind to a service right?
|
Mark M. |
AFAIK, yes, though I have never tried it
|
Yaniv S. |
ok, I'll try
|
Yaniv S. |
thanks Mark
|
Mark M. |
sorry that I did not have a more concrete suggestion for you
|
Yaniv S. |
no worries
|
Apr 30 | 9:25 AM |
Yaniv S. |
but if you happen to come up with a brilliant solution , could you mail me your idea?
|
Mark M. |
coming up with a solution out of thin air is unlikely
|
Yaniv S. |
ok:) thanks anyway . have a good day !
|
Mark M. |
you too!
|
Yaniv S. | has left the room |
Apr 30 | 9:45 AM |
Yaniv S. | has entered the room |
Mark M. |
hello again!
|
Yaniv S. |
hi again
|
Yaniv S. |
so
|
Yaniv S. |
I deleted the working client
|
Yaniv S. |
and it works!
|
Yaniv S. |
now my problem is somewhere in my service
|
Yaniv S. |
right?
|
Mark M. |
you mean the formerly-non-working client now works?
|
Yaniv S. |
yep
|
Yaniv S. |
onServiceConnected is now called
|
Mark M. |
you might now try installing the formerly-working client and confirm that it stops working
|
Mark M. |
if indeed it is no longer working, then the second client to talk to the service fails to do so, which suggests a problem on the service side
|
Mark M. |
if the formerly-working client *still* works, then perhaps this was all a misunderstanding... :-)
|
Yaniv S. |
I'll try, thanks again !
|
Yaniv S. | has left the room |
Apr 30 | 10:00 AM |
Mark M. | turned off guest access |