Chapter 6. Threads and concurrency

 

In this chapter

  • Creating and managing threads
  • Communicating between threads
  • Timers and message loops

This web of time—the strands of which approach one another, bifurcate, intersect or ignore each other through the centuries—embrace every possibility.

The Garden of Forking Paths

You’ve seen in the previous chapter how to run parts of your application as a Service, which is a great way of performing tasks that don’t require interaction with the user. These tasks are typically, continuously or periodically, executed routines, which is why it makes sense to have them run in the background. When we say background, we mean they’re not visible to the user, but it must be stressed that it does not necessarily mean they run concurrently to an application’s activities. Why is that? We have seen in the previous chapter that you can run services in separate processes, but that isn’t a requirement. In fact, unless you specify a process ID explicitly, they won’t.

6.1. Concurrency in Android

6.2. Working with AsyncTask

6.3. Miscellaneous techniques

6.4. Summary