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 trialIkuyasu Usui
36 PointsThe code does not work. The UI hangs up.
I really don't know why this happens. I think the code is exactly the same as what the video instructs. I am not a beginner programmer by the way. The main UI thread hangs up. I have included the Service in Manifest file. Do you have a working code uploaded somewhere like GitHub so I can run to check? The code up to this video lesson is fine.
2 Answers
Sachin Jayaram
5,461 PointsHi Make sure in your MainActivity when you start the service you use startService(intent); and not startActivity(intent); Its a simple error anyone can make.
Piyush Ravi
2,217 PointsI was facing the same issue. However when I closely inspected I found I was assigning the value and before starting the thread and while loop was something like this.
DownloadThread thread = new DownloadThread();
handler = thread.mHandler; // mHandler not instantiated as thread has not started
thread.setName("download thread");
thread.start();
while(handler == null) { // handler will always be null
// this goes into infinite loop
}
// correct solution below
thread.setName("download thread");
thread.start();
while(thread.mHandler == null) {
}
handler = thread.mHandler;
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherOn the 'Downloads' tab of that video you can download the project to compare with :)