Hello World on the Android Platform

29
www.greenITcenter.org DUE 0903239 Hello World on the Android Platform

description

Hello World on the Android Platform. Getting the Tools Setup. Need to Install… Eclipse (the IDE) Android SDK Java JDK (not just the JRE) Quick Start Guide is Here: http://developer.android.com/sdk/index.html. Integration. - PowerPoint PPT Presentation

Transcript of Hello World on the Android Platform

Page 1: Hello World  on the Android Platform

www.greenITcenter.org DUE 0903239

Hello World on the Android Platform

Page 2: Hello World  on the Android Platform

www.greenITcenter.org

Getting the Tools Setup

Need to Install… Eclipse (the IDE) Android SDK Java JDK (not just the JRE)

Quick Start Guide is Here:

http://developer.android.com/sdk/index.html

2

Page 3: Hello World  on the Android Platform

www.greenITcenter.org

Integration

3

Then you need to integrate Eclipse and The Android Developer Toolkit

http://developer.android.com/sdk/eclipse-adt.html

Page 4: Hello World  on the Android Platform

www.greenITcenter.org

Android SDK Versions

You then need to download SDK versions of Android to run your program against

The Android SDK Manager in Eclipse will do this

You don’t need the latest version – it’s slow API 7 (Android 2.1) is good & compatible with

most devices

Page 5: Hello World  on the Android Platform

www.greenITcenter.org

The AVD

An Android Virtual Device (a simulator) needs to be created.

You will specify this in Eclipse Includes the features that this virtual phone will

have, such as touch screen, etc.

Page 7: Hello World  on the Android Platform

www.greenITcenter.org

The Result

7

Android Virtual Device can be a little quirky and take time to load

Page 8: Hello World  on the Android Platform

www.greenITcenter.org DUE 0903239

Android Application Fundamentals

Page 9: Hello World  on the Android Platform

www.greenITcenter.org

Getting the Tools Setup

Assuming you have Eclipse And the SDK setup

9

Page 10: Hello World  on the Android Platform

www.greenITcenter.org

Android Online Tutorial

http://developer.android.com/guide/topics/fundamentals.html

10

Page 11: Hello World  on the Android Platform

www.greenITcenter.org

App Fundamentals Apps are stored in an .apk file

Components in a Program Activities – most important part Services Broadcast Receivers Content Providers Intents – a message that is sent Widgets Notifications

11

Page 12: Hello World  on the Android Platform

www.greenITcenter.org

Activities A GUI element An activity can contain views such as buttons

or check boxes

One Activity is designated (in the Manifest) as where to “start” the application

These are the “forms” of the application – the presentation layer

Page 13: Hello World  on the Android Platform

www.greenITcenter.org

Services

Not part of the GUI A background process

Playing audio Network communication Can be spawned in another thread

Page 14: Hello World  on the Android Platform

www.greenITcenter.org

Broadcast Receivers

A “listener” that receives announcements From the system – battery is low Broadcast Receivers could notify the user of

something, for example

A broadcast receiver receives an “Intent” – a message, and respond to create an event-driven application

Page 15: Hello World  on the Android Platform

www.greenITcenter.org

Content Providers

A method of interprocess communication to make data from your app available to other apps

Or, vice-versa Implemented through a ContentProvider and

a ContentResolver (to get the data). Example: The Contacts list in the phone –

your application could access this.

Page 16: Hello World  on the Android Platform

www.greenITcenter.org

Intents

The actual message that is sent

An Intent to a Broadcast Receiver might announce that a picture has been taken

You can send an Intent to another application as well.

Intents are commonly used to launch a second Activity (screen)

Page 17: Hello World  on the Android Platform

www.greenITcenter.org

Widgets

Visual components that can be added to the user’s home screen

Special broadcast receivers

Page 18: Hello World  on the Android Platform

www.greenITcenter.org

Notifications

Signal a user without interrupting the current activity.

Example – text message comes in.

We can trigger those notifications programmatically

Page 19: Hello World  on the Android Platform

www.greenITcenter.org

The Result

Think about apps as a collection of these independent pieces, passing messages to one another.

Page 20: Hello World  on the Android Platform

www.greenITcenter.org DUE 0903239

Application and ActivityClasses

Page 21: Hello World  on the Android Platform

www.greenITcenter.org

The Application Class

Your app will extend the Application class

Your application object is a singleton (only one object may be instantiated)

21

Page 22: Hello World  on the Android Platform

www.greenITcenter.org

Application Classpublic class MyApplication extends Application{

private static MyApplication singleton;

@Override public final void onCreate() {

super.onCreate(); // call the parentsingleton = this;// any other of my code

} @Override public final void onTerminate() {

super.onTerminate(); // call the parent// now my code

}

Page 23: Hello World  on the Android Platform

www.greenITcenter.org

MyApplication class

I can override… onCreate( ) onTerminate( ) – no guarantee this gets called onLowMemory( ) onConfigurationChanged( )

Need to call the superclass methods in each of your overridden methods

Sometimes the system kills your app w/ no notice

Page 24: Hello World  on the Android Platform

www.greenITcenter.org

Android Activity

The basis for the application

The program will start running here, and we can add user interface elements (such as Views) to the Activity

This is done in xml files in the ‘res’ folder

Page 25: Hello World  on the Android Platform

www.greenITcenter.org

Android Activities

import android.app.Activity;import android.os.Bundle;

public class MyActivity extends Activity{ // override the base class onCreate() }

Page 26: Hello World  on the Android Platform

www.greenITcenter.org

Activities -> Views

We need to add a view to our activity to create a GUI

Page 27: Hello World  on the Android Platform

www.greenITcenter.org

Resources

The /res folder contains xml files We can specify in xml

GUI elements (using xml is preferred to using code)

String constants to be used in the program Other resources the program needs, such as

sounds or images

Page 28: Hello World  on the Android Platform

www.greenITcenter.org

DroidDraw

DroidDraw can help with the screen layouts

http://www.droiddraw.org/

Page 29: Hello World  on the Android Platform

www.greenITcenter.org

Styles and Themes

You can also create a style for all of the Activities in your app

Similar to css for web pages

http://developer.android.com/guide/topics/ui/themes.html