An
Android application consists out of the following parts:
- Activity – Represents the presentation layer of an Android application, e.g. a screen which the user sees. An Android application can have several activities and it can be switched between them during runtime of the application.
- Views – The User interface of an Activities is build with widgets classes which inherent from “android.view.View”. The layout of the views is managed by “android.view.ViewGroups”.
- Services – perform background tasks without providing an UI. They can notify the user via the notification framework in Android.
- Content Provider – provides data to applications, via a content provider your application can share data with other applications. Android contains a SQLite DB which can serve as data provider
- Intents are asynchronous messages which allow the application to request functionality from other services or activities. An application can call directly a service or activity (explicit intent) or ask the Android system for registered services and applications for an intent (implicit intents). For example the application could ask via an intent for a contact application. Application register themself to an intent via an IntentFilter. Intents are a powerful concept as they allow to create loosely coupled applications.
- Broadcast Receiver – receives system messages and implicit intents, can be used to react to changed conditions in the system. An application can register as a broadcast receiver for certain events and can be started if such an event occurs.
Other
Android parts are Android
widgets or Live Folders and Live Wallpapers . Live Folders display any source of data on
the homescreen without launching the corresponding application.
Security and permissions
Android defines
certain permissions for certain tasks. For example if the application want to
access the Internet it must define in its configuration file that it would like
to use the related permission. During the installation of an Android
application the user get a screen in which he needs to confirm the required
permissions of the application.
AndroidManifest.xml
An Android
application is described the file “AndroidManifest.xml”. This file must declare
all activities, services, broadcast receivers and content provider of the
application. It must also contain the required permissions for the application.
For example if the application requires network access it must be specified
here. “AndroidManifest.xml” can be thought as the deployment descriptor for an
Android application.
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.temperature"
android:versionCode="1"
android:versionName="1.0">
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity
android:name=".Convert"
android:label="@string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion="9" />
</manifest>
The
“package” attribute defines the base package for the following Java elements.
It also must be unique as the Android Marketplace only allows application for a
specific package once. Therefore a good habit is to use your reverse domain
name as a package to avoid collisions with other developers.
“android:versionName”
and “android:versionCode” specify the version of your application. “versionName”
is what the user sees and can be any string. “versionCode” must be an integer
and the Android Market uses this to determine if you provided a newer version
to trigger the update on devices which have your application installed. You
typically start with “1” and increase this value by one if you roll-out a new
version of your application.
“activity”
defines an activity in this example pointing to the class “de.vogella.android.temperature.Convert”.
For this class an intent filter is registered which defines that this activity
is started once the application starts (action android:name=”android.intent.action.MAIN”).
The category definition (category android:name=”android.intent.category.LAUNCHER”
) defines that this application is added to the application directory on the
Android device. The @ values refer to resource files which contain the actual
values. This makes it easy to provide different resources, e.g. strings,
colors, icons, for different devices and makes it easy to translate
applications. The “uses-sdk” part of the “AndroidManifest.xml” defines the
minimal SDK version your application is valid for. This will prevent your
application being installed on devices with older SDK versions.
No comments:
Post a Comment