Introduction to Android 2 application development |
Written by Sing Li | |||||||
Wednesday, 25 August 2010 | |||||||
Page 3 of 6
Listing 1 shows a very basic Activity - the IProgrammerActivity. Listing 1.package info.iProgrammer.android; In fact, you will become very familiar with Activities similar to the one shown in Listing 1. It is Android's entry point into your application - whenever Android deems to be ready. It is your responsibility, in coding this Activity, to set up and tell the Android platform everything that your application will need - so that the one in control, i.e. the Android Platform, can call you back again or rather your app's custom workings when it needs them. On an Android device, every application runs within its own restricted Java VM (an Android specific Dalvik VM) in a separate process. Making Sense of Android ActivitiesAndroid learns about the initial Activity of your App through a configuration file that every Android application must have, named AndroidManifest.xml. Listing 2 shows the AndroidManifest.xml with the XML lines that tell Android about our main hook IProgrammerActivity highlighted. Listing 2<?xml version="1.0" encoding="utf-8"?> Accessing String Resources in Android ApplicationsThe @string/app_name and @drawable/icon notations within AndroidManifest.xml refers to named resources specified in another XML file. The actual string value for @string/app_name resource is actually located in an XML resource file, res/values/string.xml, see Listing A. Named resources enable you to write Java code and create configuration files without hard-coding of text strings and other resources - such as a graphical icon for the App. You just specify the string or resource you need via a name, and the platform or the compilation/assembly mechanism will fetch the actual string or resource for you. By giving up direct control here, some magic can occur. For example, you ask for the string named @string/thankyou, and the platform can detect if your App is running on an English or a Chinese Smart Phone, and then fetch either the English "Thank you!" or the Chinese "谢谢!" string for you. All of a sudden, without recompiling the code, your application can work internationally! Relinquishing control does have its benefits. Listing A<?xml version="1.0" encoding="utf-8"?> <ASIN:0132121360> <ASIN:1430224193> <ASIN:1430226471><ASIN:0981678017> <ASIN:0672330768> <ASIN:1430232765> |
|||||||
Last Updated ( Sunday, 19 September 2010 ) |