Beautiful.  Thank you very much.

>
> 2. How does the Android phone use Looper to coordinate message
>
> > handling?
>
> Not sure what you mean by "coordinate" in this context.

Apologies about being vague here.  I'm trying to envision the call
stack from the phone's perspective when it sends a message to the
Looper created in my thread.  I looked at the code for Looper and got
minimal insight: looks like Looper registers itself with a lower level
API call?  What gets registered?

How does Looper know what handler class to send messages to?  And,
where does it get its messages from in the first place?  When I have a
thread that calls Looper.prepare(), then Looper.loop(), then
Looper.exit(), it's not clear how Looper is getting messages for my
class.  Looper.loop() looks like it blocks.  So, how do I make sure
Looper.loop() doesn't stall my thread waiting for messages?

And, in the case where I want a message handler to process messages in
a different thread, it's not clear how Looper knows what class to send
the messages to.  The messages just seem to "come out of the sky" from
somewhere.


>
> 3. What do I need to do when I get the "Can't create handler inside
>
> > thread that has not called Looper.prepare()" message?
>
> You call Looper.prepare() before you create the Handler, then some time
> later you call Looper.loop() to start the message handling loop, exactly as
> done in the sample code at the top 
> ofhttp://developer.android.com/reference/android/os/Looper.html
> If you don't want your message processing to be done in that thread, create
> the Handler somewhere else (your main application thread for example).

Sounds good - I am envisioning my thread receiving messages somehow.
Perhaps that's my problem here.  With Looper.prepare() being called in
my thread, how do I redirect the messages to the handler?  How do I
tell my thread to tell Looper where the handler is?

>
> 4. How do I use LocationManager.requestLocationUpdates with Looper,
>
> > and why does this call require a Looper object?
>
> Because internally those updates are sent as Messages, so a Handler is
> needed to receive them, so you need a Looper to run the message loop.
> You don't *have* to specify a Looper, but in that case the calling thread
> must have a Looper. For example, you can call the non-Looper method from
> your app's main thread.

I got around my problem here by calling requestLocationUpdates
(LocationManager.GPS_PROVIDER, 0, 0, locListen, Looper.getMainLooper
()).  What's confusing about this is that I'm expecting locListen to
just have gotten the messages anyway like a normal callback.  This
suggests, then, that the application's main message handler is being
used to dispatch messages to locListen.  Right?

Thanks for all your help.

Richard Schilling
Root Wireless

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to