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 trialvicente lee
6,271 PointsWhy doesn't the toast show up on the very first click?
Why doesn't the toast show up on the very first click. I get why it won't show up if you press it a bunch of times, because the download method is blocking, but shouldn't the first onClick show the toast?
2 Answers
Ben Deitch
Treehouse TeacherFrom the Toast.show() method, it looks like when we call .show() on a Toast object that it triggers a call to 'enqueueToast(...)'.
While we would normally think that the show() method happens immediately, it looks like it doesn't. So my guess is that downloadSong is called before Android actually shows the Toast, and then the Toast is 'shown' while the UI is locked up which causes us to not be able to see it.
Boban Talevski
24,793 PointsIf I'm getting this right, this means that the creation of the Toast is actually happening in a separate thread and it's passed back to the main thread to be shown when that other thread creates it. But since the main thread is asleep at this time, it can't show it...or as Ben says, it is "showing it" while it's asleep (which is the reason we don't see it) and by the time the main thread wakes up it has already disappeared.