The document discusses creating a simple "Hello World" Android application. It covers setting up the Android development environment, creating an Android project with an activity class, defining UI layouts with XML, setting strings and references, and introducing and fixing bugs. The goal is to create an app that displays "Hello World" when run on a device or emulator.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
29 views
Hello World
The document discusses creating a simple "Hello World" Android application. It covers setting up the Android development environment, creating an Android project with an activity class, defining UI layouts with XML, setting strings and references, and introducing and fixing bugs. The goal is to create an app that displays "Hello World" when run on a device or emulator.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16
Android Introduction
Hello World
@2010 Mihail L. Sichitiu 1
Goal Create a very simple application Run it on a real device Run it on the emulator Examine its structure
@2010 Mihail L. Sichitiu 2
Google Tutorial We will follow 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
@2010 Mihail L. Sichitiu 3
Package Content All source code here Java code for our activity
Activity An Android activity is focused on a single thing a user can do. Most applications have multiple activities
@2010 Mihail L. Sichitiu 6
Activities start each other
@2010 Mihail L. Sichitiu 7
Revised HelloAndroid.java package com.example.helloandroid; Inherit from the import android.app.Activity; Activity import android.os.Bundle; Class import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello, Android – by hand"); setContentView(tv); } } Set the view “by hand” – from the program @2010 Mihail L. Sichitiu 8 Run it!
@2010 Mihail L. Sichitiu 9
/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
import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } Set the layout of the view as described in the main.xml layout @2010 Mihail L. Sichitiu 12 /gen/R.java package com.example.helloandroid; public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; } public static final class id { public static final int textview=0x7f050000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Object o = null; o.toString(); setContentView(R.layout.main); } }