Professional Documents
Culture Documents
Unit 1 - 2 - Contd PDF
Unit 1 - 2 - Contd PDF
Hello World
1
Goal
Create a very simple application
Run it on a real device
Install drivers for device
Connect device to PC via USB cable
make sure turned on USB debugging
(settings -> Application -> Development)
Also turn on install of non market Apps
(settings->Application->Unknown Sources)
Device will be recognized within Eclipse
OR
Run it on the emulator
Examine its structure
2
3
Consider the tutorial at:
http://developer.android.com/resources/tut
orials/hello-world.html
Start Eclipse (Start -> All Programs ->
Eclipse)
Create an Android Virtual Device (AVD)
Create a New Android Project
4
Package Content - Overview
All source code here Java code for our activity
Android Manifest
5
@2011 Mihail L. Sichitiu 6
@2011 Mihail L. Sichitiu 7
@2011 Mihail L. Sichitiu 8
The Main Activity File
The main activity code is a Java
file MainActivity.java.
This is the actual application file which
ultimately gets converted to a Dalvik
executable and runs the application.
11
The Manifest File
Each component developed as a part of
application, must declare all its
components in a manifest.xml
This resides at the root of the application
project directory.
This file works as an interface between
Android OS and your application
If the components are not declared in this
file, then it will not be considered by the
OS.
</application>
</manifest>
13
Following is the list of tags which are used
in manifest file to specify different Android
application components:
<activity>elements for activities
<service> elements for services
<receiver> elements for broadcast
receivers
<provider> elements for content providers
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="hellworld" />
29
Activities start each other
30
Revised HelloAndroid.java
package com.example.helloandroid; Inherit
from the
import android.app.Activity; Activity
import android.os.Bundle; Class
import android.widget.TextView;
32
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
Further redirection to
/res/values/strings.xml
33
/res/values/strings.xml
34
HelloAndroid.java
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
36
Run it!
37