Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

How do I make downloading from and uploading to Google Tasks from my ToDo List app work consistently?

Hi. I'm working on the 7th project--Making a ToDo List App--in the Android Development Techdegree track. I have the main features working but am having some problems with downloading from and uploading to Google Tasks. The first time I download or upload, everything works fine. But in subsequent tries, the app freezes. I don't know why this is. could you guys take a look at my code, especially in the MainActivity file, toward the end, and tell me what I'm doing wrong? Here is a link to my project: https://github.com/slim0926/ToDoList Thanks so much, Sue

1 Answer

Seth Kroger
Seth Kroger
56,403 Points

One thing that stands out to me is you're join()ing your threads immediately after start()ing them. Doesn't that defeat the purpose of using a background thread in the first place?

Does it? I'm sorry I'm completely lost. The reason why I did that is because I needed to know when the background thread finished the work so that I could close the dialog fragment and update my recyclerview of tasks.

Seth Kroger
Seth Kroger
56,403 Points

join() stops the current thread (the main UI thread in this case) and waits for the joined thread to finish. This is the main reason your app locks up. There are other means of waiting for the thread, such as using runOnUiThread() to call a method to update the view.

Thanks! I will try that.