Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Threads and Services Threads in Android Upgrading Our Thread

I need some clarification about Looper and mHandler (t=01:37)

I've spent several hours re-watching the video, making pages of notes, trying to understand these new concepts (e.g. Message, Looper, etc), and I believe I almost got it. I have a few questions about the content in class DownloadThread.java.

Q.1) Is the mHandler object created during initial run (when thread.start() is executed, see class MainActivity.java) even when no messages are sent (because the mDownloadButton was not clicked)? If it was created during initial run, it would miss an argument for downloadSong method in DownloadHandler.java.

Q.2) Can the following be confirmed: When a message is processed by the mHandle object it will not cease to exists (i.e. not re-instantiated)?

For illustrative purposes:

Looper.prepare()
mHandler     // instantiated from DownloadHandler class
Looper.loop() 
(a message arrives)
mHandler     // takes arbitrary data attached to message (when queryButton is clicked)
downloadSong(message)    // pass data attached to message as argument to method (DownloadHandler.java)
Looper.loop()
(a message arrives)
mHandler     // takes arbitrary data attached to message (when queryButton is clicked)
downloadSong(message)    // pass data attached to message as argument to method (DownloadHandler.java)

Thanks in advance,