Understanding Android AsyncTask (Executing Background Tasks)

The AsyncTask Android class lets us sort of bind background tasks to the UI thread. So using this class, you can perform background operations and then publish the results to the UI thread that updates the UI components. This way you won’t have to deal with threads, handlers, runnables, etc. directly yourself. It’s sort of a helper class around Thread and Handler.

Continue reading “Understanding Android AsyncTask (Executing Background Tasks)”

Understanding Android/Java Processes and Threads Related Concepts (Handlers, Runnables, Loopers, MessageQueue, HandlerThread)

In this article we’ll try to briefly go through the various sort of low level concepts in Android that are really important to understand IMHO. Once you have a good grasp on these, a lot of things that are actually built atop these concepts become much easier to understand and code. We’ll go through processes, threads, loopers, message queues, messages, handlers, runnables, etc. I’ll also point to various external resources that you should definitely go through for a much better understanding.

Continue reading “Understanding Android/Java Processes and Threads Related Concepts (Handlers, Runnables, Loopers, MessageQueue, HandlerThread)”

Android Interprocess Communication (IPC) with AIDL

Two processes cannot share memory and communicate with each other directly. So to communicate, objects have to be decomposed into primitives (marshalling) and transfered across process boundaries. To do this marshalling, one has to write a lot of complicated code, hence Android handles it for us with AIDL (Android Interface Definition Language). You should read the previous article on the binder framework to get some more idea.

Continue reading “Android Interprocess Communication (IPC) with AIDL”

An Overview of Android Binder Framework

In the Linux OS, there are several techniques to achieve IPC (Inter-process communication) like files, sockets, signals, pipes, message queues, semaphores, shared memory, etc. However, Android’s modified Linux kernel comes with a binder framework which enables an RPC (remote procedure call) mechanism between the client and server processes, where the client process can execute remote methods in the server process as if they were executed locally. So data can be passed to the remote method calls and results can be returned to the client calling thread. It appears as if the thread from the client process jumps into another (remote) process and starts executing in there (known as Thread Migration).

Continue reading “An Overview of Android Binder Framework”

Asynchronous Background Execution and Data Loading with Loaders (Framework) in Android

Android has this Loader framework that offers a powerful (yet simple) way to asynchronously load data from content providers or other data sources like an SQLite database, network operation, et al. in an Activity or a Fragment (clients).

Continue reading “Asynchronous Background Execution and Data Loading with Loaders (Framework) in Android”

Using AsyncQueryHandler to Access Content Providers Asynchronously in Android

In our previous posts we discussed SQLite access and Content Providers. Now access to a content provider will involve accessing some sort of persistent storage like a database or a file under the hood. Accessing a storage can be a long task and hence this should not be executed on the UI thread which will delay the rendering and could even lead to ANRs. Hence, background threads should be responsible for handling provider’s execution.

Continue reading “Using AsyncQueryHandler to Access Content Providers Asynchronously in Android”