English subtitles

← Main Thread vs Background Thread - Developing Android Apps

Get Embed Code
10 Languages

Showing Revision 14 created 05/24/2016 by Udacity Robot.

  1. When we said that the framework didn't want us
  2. to run network operations on the main thread, what
  3. is the main thread? Well, Android apps run by
  4. default on the main thread, also called the UI thread.
  5. It handles all the user input as well as
  6. the output, such as screen drawing. Thus we want
  7. to avoid any time-consuming operations here, otherwise the URI
  8. is going to stutter. Instead, kick off a background worker
  9. thread if you have to do some long-running
  10. work. This includes doing network calls, decoding bitmaps, or
  11. reading, and writing from the database. Okay. So, somehow,
  12. we have to move the networking code off the
  13. main thread. But how are we going to do
  14. that? Well there are several options, but let's look
  15. for the name of the Android class that simplifies
  16. background thread creation and UI thread synchronization, so that
  17. the results from the background work will come back onto the
  18. main thread, and then we can use it to update our
  19. UI. Search online and figure out the answer to this question
  20. and then enter the class name in the box. Here's some
  21. advice for you. If you ever get stuck on how to
  22. do something in Android and you can't find it on the
  23. developer's site you can try to check stackoverflow.com. It's a question
  24. and answer site that many Android developers use as a valuable resource.
  25. So chances are likely that someone has
  26. already asked a similar question that you have.