In the last post we created an android application. Let us see some features of an android application.
An application can consist of
Activity, Service or Broadcast receivers are started by sending an asynchronous message called intent. Content provider is started when it is targeted by a content resolver. In some cases, if the intent object is provided with the action to perform, the android system selects appropriate activity and starts it. e.g. if the intent specifies view action for a web page, then the browser is started.
Manifest file :
All components of an activity must be mentioned in a file called AndroidManifest.xml file. This manifest file must be located at the root of the android application. If a component is not mentioned in this manifest file, then android system can not start that component.
A sample manifest file looks like this
As you can see, the manifest file also specifies the minimum sdk version, the permissions for the app, the hardware requirements like bluetooth, camera etc.
Resources
If you look at the app in package explorer, you can see along with src (source) folder, another folder res (resource). The resource folder contains the images for the app, layout files for activities, menus, styles, colors etc. Resources are stored in different sub-folders such as res/layout/main_activity.xml, res/drawable/ldpi/logo.png etc. Sdk tools will create a unique resource id for each of the resources in the form - R.drawable.logo, R.layout.main_activity etc.
And to end our discussion, let us see what are the various components android sdk provides us for development.
SDK Tools
Emulator:
You can test run your apps on emulator, instead of actual phones. You can select a virtual device with different versions of android, different hardware configuration. The emulator can be started from eclipse or from shell. The emulator can even emulate sms messages, internet etc, but not camera or bluetooth.
DDMS : Dalvik debug monitoring service lets you debug your application. You can inspect the memory, you can kill any process, you can set break points etc.
ADB : Android debug bridge lets you communicate with the android emulator or device. Adb provides you commands to install and uninstall an app, push or pull a file, start a linux shell for the device or virtual device.
AAPT : Android asset packaging tool converts all the resource file of android application into aidl file. Java compiler converts aidl file and java source file together into .class files.
dex : dex tool converts .class file into dalvik byte code called .dex file.
apk builder : converts .dex file into file .apk file which can be installed on the phones.
Don't worry too much about these terminology. Eclipse will take care of all these tools. And if you want to debug the application, you can use ddms perspective.
- Android OS is a multi-user Linux OS.
- Each application has its own user id.
- Each process in the application runs in its own virtual machine. But android apps do not use JVM. They use a VM called dalvik virtual machine.
- Every application runs in its own process
- Android implements principle of least privilege. That is to say each application can access its own data and resources, but not the those of other applications.
- But apps can access device data such as contacts, SMS etc by requesting permission from the user at install time.
An application can consist of
- Activity : single screen with user interface. An app can start any of its activities and also activities of other apps.
- Service : It is a background component which does a long running operation like conversion from text to speech. It does not have a user interface.
- Content provider : this manages shared data. Your app can store the data in file, sqlite database etc and other apps can access this data using content provider.
- Broadcast receiver : receives system wide broadcast announcement like turning off of the display, arrival of a SMS message etc. Does not have user interface, but can display a message on status bar.
Activity, Service or Broadcast receivers are started by sending an asynchronous message called intent. Content provider is started when it is targeted by a content resolver. In some cases, if the intent object is provided with the action to perform, the android system selects appropriate activity and starts it. e.g. if the intent specifies view action for a web page, then the browser is started.
Manifest file :
All components of an activity must be mentioned in a file called AndroidManifest.xml file. This manifest file must be located at the root of the android application. If a component is not mentioned in this manifest file, then android system can not start that component.
A sample manifest file looks like this
As you can see, the manifest file also specifies the minimum sdk version, the permissions for the app, the hardware requirements like bluetooth, camera etc.
Resources
If you look at the app in package explorer, you can see along with src (source) folder, another folder res (resource). The resource folder contains the images for the app, layout files for activities, menus, styles, colors etc. Resources are stored in different sub-folders such as res/layout/main_activity.xml, res/drawable/ldpi/logo.png etc. Sdk tools will create a unique resource id for each of the resources in the form - R.drawable.logo, R.layout.main_activity etc.
And to end our discussion, let us see what are the various components android sdk provides us for development.
SDK Tools
Emulator:
You can test run your apps on emulator, instead of actual phones. You can select a virtual device with different versions of android, different hardware configuration. The emulator can be started from eclipse or from shell. The emulator can even emulate sms messages, internet etc, but not camera or bluetooth.
DDMS : Dalvik debug monitoring service lets you debug your application. You can inspect the memory, you can kill any process, you can set break points etc.
ADB : Android debug bridge lets you communicate with the android emulator or device. Adb provides you commands to install and uninstall an app, push or pull a file, start a linux shell for the device or virtual device.
AAPT : Android asset packaging tool converts all the resource file of android application into aidl file. Java compiler converts aidl file and java source file together into .class files.
dex : dex tool converts .class file into dalvik byte code called .dex file.
apk builder : converts .dex file into file .apk file which can be installed on the phones.
Don't worry too much about these terminology. Eclipse will take care of all these tools. And if you want to debug the application, you can use ddms perspective.