Developing First Android Application – Step by Step
Before moving below steps we assume that Eclipse ADT is already installed in your system and developer is familer with basic IDE features.
1. Create New Android Application Project
File–>New–>Android Application Project
Provide necessary detaiils as shown in screens below.
After project creation you will see a window as below.
Project/Package Explore Listings:
Activity Class(Reference taken from Android official developer docuement):
An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup). There are two methods almost all subclasses of Activity will implement:
- onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically.
- onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data).
To be of use with Context.startActivity(), all activity classes must have a corresponding declaration in their package’s AndroidManifest.xml.
Layout File/ UI Design: activity_hello.xml
AndroidManifest.xml (Reference taken from official reference document):
Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest file presents essential information about your app to the Android system, information the system must have before it can run any of the app’s code. Among other things, the manifest does the following:
1. It names the Java package for the application. The package name serves as a unique identifier for the application.
2. It describes the components of the application — the activities, services, broadcast receivers, and content providers that the application is composed of. It names the classes that implement each of the components and publishes their capabilities (for example, which Intent messages they can handle). These declarations let the Android system know what the components are and under what conditions they can be launched.
3. It determines which processes will host application components.
4. It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
5. It also declares the permissions that others are required to have in order to interact with the application’s components.
6. It declares the minimum level of the Android API that the application requires.
Elements of this file:
AndroidManifest.xml from our Example:
2. Configure AVD- Emulator to Test Application:
Window–>Android Virtual Device Manager
AVD Configuration parameters as per the device requirement. Here a basic configuration is given for testing android apps.
After starting ADV you will see a screen as below.
3. Running First Android App Developed in Step-1:
Output screen after run: