Ready to start
This article describes several of the Android SDK tools that handle complex situations. Developing Android apps requires the latest version of the Android SDK, which requires a Java Development Kit (JDK). I am using the Android 2.2 and JDK 1.6.0_17. Physical devices are not required; All the code in this article works well on the Android emulator that comes with the SDK. This article assumes that you are familiar with Android programming and do not involve Android Foundation development, but it is also possible if you have knowledge of the Java programming language.
Concurrency and networking
Common abbreviations
API: Application Programming Interface
SQL: Structured Query Language
SDK: Software Development Kit
UI: User Interface
XML: Extensible Markup Language
One of the most common tasks of an Android application is to retrieve data or send data over a network to a remote server. The result of this operation is usually some new data that you want to show to the user. This means that you need to modify the user interface. Most developers know that you will not perform a potentially long-running task, such as accessing data over the network on the main UI thread (especially with a very slow phone with a network connection). Freeze your application until the long-running task completes. In fact, if the task exceeds 5 seconds, the Android operating system will have the infamous application not responding dialog box, as shown in Figure 1.
Figure 1. Android Infamous application not responding dialog box
You cannot know how slow a user's network connection can be. To avoid risk-taking, you must perform a task on a different thread, or at least not on the main UI thread. Many Android applications, but not all, need to handle multiple threads, which causes concurrency. The Android database is a good choice for applications that often need to save data locally. These three scenarios (different threads, concurrent and locally saved data) have many standard methods to process in the Java environment. However, as you will see, Android offers a different choice. Let's look at it one by one to see its pros and cons.