Free Android app covering all aspects of addiction, including prevention and treatment

Using Threads Tutorial

Forget the grass, get off the Main thread!

Android threads tutorial icon

Have you read the article on Processes and Threads yet?

Always remember the two most important rules when working with threads:

  • Don’t block the Main thread
  • Don’t try and access the UI directly from the worker thread

Speed up your apps response times. Move all processing and I/O operations off the main thread. Do the work in a child thread. Our tutorial will show you how.

AsyncTasks do it in the background

The golden thread

asyncTask tutorial icon

All Android components (like activities and services) start on the main thread. This is the thread that the user interacts with.

You need to keep this thread clear so that the app does not hang. It’s a good idea to put all time-consuming processes on a separate thread.

Put file operations, network lookups, database interaction, etc. on a background thread.