Calls through aidl interfaces are dispatched from a thread pool, so there is
no issue there.  The thread that is blocked waiting does NOT sit in an event
loop, and simply blocks, so you service shouldn't take a long time doing its
work or the app will ANR.  If the call will take a long time the service
needs to do the work asynchronously in another thread and return the result
to the caller asynchronusly through a callback.

Things work fine for background services; I don't know why you think
otherwise, they are used all over the place (and I don't really know what
this has to do with whether or not you wait asynchronously for a binding).
And the only async part is binding to the service itself; after that you
have an aidl interface you can make direct calls through, though with the
caveat that the other side needs to deal with multithreaded calls into it.

Finally, if you just want to have a service for which you deliver work and
don't wait, you can use the startService() model where your command is
delivered in an Intent.

On Wed, Jun 17, 2009 at 10:25 PM, Craig <supkic...@gmail.com> wrote:

>
> Ok, fair enough. But you allow synchronous calls to services via aidl,
> which presumably spin in an event handling loop deep in the framework
> code, waiting for a return from the service. Why couldn't the same be
> done for service initialisation?
>
> And now that we've established that it isn't possible, what on earth
> is the workaround? What good is a remote api if I can't call it
> reliably? It seems you've set up the system to work for interactive
> apps, but haven't catered by background/service apps.
>
> thanks,
> Craig
>
>
> On Thu, Jun 18, 2009 at 3:00 PM, Dianne Hackborn<hack...@android.com>
> wrote:
> > Correct this is async.  I certainly hope we will never ever allow for
> nested
> > event loops.
> >
> > On Wed, Jun 17, 2009 at 9:36 PM, Craig <supkic...@gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> I suspect this is not possible, but maybe there is a suggested
> >> solution...
> >>
> >> I want to call an aidl method on a service (the TTS service), from my
> >> service. I want to lazy load TTS only when I need it. e.g.
> >>
> >> class MyService extends Service {
> >> private void generateAudioFromText(String text) {
> >>  TTS tts = new TTS(...);
> >>  ...
> >>  //wait for TTS service to start up
> >>  ...
> >>  tts.synthesizeToFile(text, ...);
> >> }
> >>
> >> The problem is that this function is called on the main thread, and
> >> the TTS constructor requires waiting for the TTS service to startup,
> >> which also returns on the main thread. Thus there seems to be no way
> >> to wait in that function without deadlocking the app.
> >>
> >> Other frameworks allow you to check the message queue yourself while
> >> waiting, but Android doesn't appear to allow this. e.g. I want to do
> >> something like:
> >>
> >> while(true) {
> >>  Looper.getMainLooper().dispatchNextMessageInQueue()
> >>  if(the TTS service has initalised ok, or timeout)
> >>    break;
> >> }
> >>
> >> Any ideas?
> >>
> >> Craig
> >>
> >
> >
> >
> > --
> > 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, and so won't reply to such e-mails.  All such
> > questions should be posted on public forums, where I and others can see
> and
> > answer them.
> >
> >
> > >
> >
>
> >
>


-- 
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, and so won't reply to such e-mails.  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-framework" group.
To post to this group, send email to android-framework@googlegroups.com
To unsubscribe from this group, send email to 
android-framework+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/android-framework?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to