Android applications generally have four types of components:
- An activity represents a single screen with a user interface. An application can have multiple independent activities.
- A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. For example, a service might play music in the background while the user is in a different application.
- A content provider manages shared application data. Other applications can query or even modify the data through the content provider.
- A broadcast receiver is a component that responds to system-wide broadcast announcements. A typical broadcast receiver might initiate a service to perform some work based on the event.
It is important to understand that any application can start another application’s component… but only indirectly as Android runs each application in a separate process. To do that, the application must deliver a message to the system that specifies its intent to start a particular component in a different application. The system then activates that component.
Work to do
Let’s start quickly. The first step is to setup the development environment as explained in the previous topic: (Java, Eclipse, Android SDK and Platform Tools).
At this point, it is possible to create an Android Virtual Device (AVD) and run an emulator.
The next step is to launch Eclipse, install (if needed) and configure the Android Development Tools plugin and start developing Android applications!
HelloWorld
The first application to develop is HelloWorld which should simply display a nice message in an activity when launched. The content of HelloWorld should be explored (AndroidManifest.xml, bin/, libs/, res/, src/, assets/, gen/ and proguard.cfg) and understood. HelloWorld should be launched in an Android emulator to check whether it’s working correctly. It is also interesting to launch it on a real Android devices (because we can) 🙂
Now
The second application to develop is called Now. It displays one button which fills in the whole of its activity. When the button is clicked, the current date and time will be updated in the button’s label.
The way to do that is to add an Android button to the activity, setOnClickListener appropriately (i.e. to update the label to the current date and time). The easiest way to do that is to use a Java inner class at this point.
The AndroidManifest.xml generated by Eclipse contains an activity, an intent-filter whose purpose is to make the activity appear in the launcher and, very importantly, specifies a minSdkVersion (which is an integer corresponding to a specific version of Android) and, optionally, a targetSdkVersion:
- 1 = Android 1.0 (obsolete)
- 2 = Android 1.1 (obsolete)
- 3 = Android 1.5
- 4 = Android 1.6 (obsolete)
- 5 = Android 2.0 (obsolete)
- 6 = Android 2.0.1 (obsolete)
- 7 = Android 2.1
- 8 = Android 2.2
- 9 = Android 2.3-2.3.2 (obsolete)
- 10 = Android 2.3.3-2.3.7
- 11 = Android 3.0
- 12 = Android 3.1
- 13 = Android 3.2
- 14 = Android 4.0-4.0.2
- 15 = Android 4.0.3-4.0.4
NowReloaded
The next application to be developed is an enhanced version of Now which, instead of using Java code to create a button uses an XML-layout generated graphically by the ADT plugin in Eclipse.
The Java code needs to be modified to use findViewById and care must be taken to really understand the difference between wrap_content and fill_parent (renamed to match_parent as from API level 8).
Forex
The next application is called Forex and allows the user to enter an amount in USD and, when the convert button is clicked, the MUR amount is calculated and displayed.
Airplanes
The application to build displays different airplanes based on which of the three radio buttons has been clicked on. The essential aspect of this application is that the radio buttons are found within a RadioGroup.
Leave a Reply