android development

48
ANDROID DEVELOPMENT KELLY MCBEAN

Upload: elkan

Post on 23-Feb-2016

49 views

Category:

Documents


1 download

DESCRIPTION

Android Development . Kelly McBean. Development Environment Overview. Eclipse Standard IDE for Developing Android Applications Install: Java (JDK) – Since Eclipse Runs on top of Java Eclipse Standard Using Eclipse “Install Software” Developer Tools (Plugins) Android SDK - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Android  Development

ANDROID DEVELOPMENT

KELLY MCBEAN

Page 2: Android  Development

DEVELOPMENT ENVIRONMENTOVERVIEW

EclipseStandard IDE for Developing Android

Applications

Install:1. Java (JDK) – Since Eclipse Runs on top of Java2. Eclipse Standard3. Using Eclipse “Install Software”

1. Developer Tools (Plugins)2. Android SDK3. Android APIs

Page 3: Android  Development

TESTING FOR JAVA

http://java.com

If you get the Congratulations message, skip to Installing Eclipse…else continue with the Java Install

Page 4: Android  Development

INSTALLING JAVA

Install Documentation:

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

Java Platform (JDK)http://www.oracle.com/technetwork/java/javase/downloads/index.html

Page 5: Android  Development

INSTALLING JAVA

Install latest version * for appropriate OS* At this time 7u25 is the latest

Page 6: Android  Development

INSTALLING ECLIPSE

Downloads:http://www.eclipse.org/downloads

Install:1. Save file to a temp folder2. Open Zip file and copy the eclipse to root

(c:\)3. Run eclipse from c:\eclipse\eclipse.exe4. Accept the default workspace

Page 7: Android  Development

INSTALLING PLUG-IN

From Inside Eclipse:Menu: Help > Install New Software…

Work with: http://dl.google/android/eclipse

After Accepting License Agreement Eclipse will reboot and continue with installing SDK

Page 8: Android  Development

INSTALLING SDK

Note the Target Location

Accept All

And Wait…

Page 9: Android  Development

INSTALLING APIThe Android APIs are the Android platforms (i.e. 2.2, 4.1, etc.)

By Default, only One API is installed

To check on Installed Android APIs:Windows > PreferencesAndroid Tab

Optional: Menu: Windows > Android SDK Manager

Choose Additional APIs to Install

Page 10: Android  Development

VIRTUAL DEVICES (AVD)

The AVD is an emulator instance that enables you to model an actual device

APIs are available to emulate many of the most popular Android devices

While tethering a device through a USB connection is possible, AVDs are invaluable for testing applications

Page 11: Android  Development

CREATING A VIRTUAL DEVICE

The AVD is an emulator instance that enables you to model an actual device

You will need one for each API you want to test…

Menu: Windows > AVD Manager

Page 12: Android  Development

UPDATE ENVIRONMENT PATH

My Computer. Properties. Advanced

Add “C:\android-sdks\tools; C:\android-sdks\platform-tools” to …

Environment . System . Path

Optional?

Page 13: Android  Development

ECLIPSE DEVELOPMENT ENVIRONMENT FOR ANDROID

The Eclipse Development Environment should be ready to go…

Page 14: Android  Development

CREATING ANDROID APPLICATION

Application Name is shown in Play Store

Project Name must be unique within Android Workspace

Package Name is a Unique Identifier for the Application

Page 15: Android  Development

ANDROID PLATFORM DISTRIBUTION

Page 16: Android  Development

ANATOMY OF AN ANDROID APPLICATION

src – Contains the Java source files for the project

gen – Contains the R.java file, a compiler-generated file that references all the project resources

res – All the project resources. Also contains subfolders to support devices with different size screen resolutions and densities

values – Contains string constants for the application

AndroidManifest – The manifest for the Android application includes the Intents for the Activities and any permissions needed by the application

Page 17: Android  Development

ACTIVITIES AND INTENTS

An Activity is a window that contains the user interface

An application can have zero or more activities

In Android, you navigate between Activities through what is known as an intent

Intents enable different activities from different applications to work together

Page 18: Android  Development

DIALOG WINDOWS

o Dialog windows are used to display information and sometimes to get confirmation from the user

o Common Dialog Windows consist of:o Toast

o A message that pops up on the bottom of the user screen for a short period of time

o Alert Dialog Windowo Displays choices to the user and waits

for a responseo Progress Dialog Window

o Useful for displaying the progress of a process

Page 19: Android  Development

TOAST DIALOG

A toast provides simple feedback in a small popup

Toasts take 3 parameters1) Application Context2) Text Message3) Duration

OR

Page 20: Android  Development

ALERT DIALOG

Alert Dialog gets a confirmation from the user

Code to handle the following eventsPositive: Typically “OK”Negative: Typically “Cancel”MultiChoice: When the user selects

from a list

Page 21: Android  Development

PROGRESS DIALOG

Page 22: Android  Development

INTENTS

o In Android, you navigate between activities through what is known as an intent

o Results can be returned from an Intento Data can also be passed using Intent Objecto Built-in applications can be called using Intents

o Web Browsero Phone Dialero Contactso Mapo Etc.

Page 23: Android  Development

WEB BROWSER & PHONE INTENT

Page 24: Android  Development

NOTIFICATIONSA notification is a message displayed to the user outside of the applications UI

To see the details of the notification, the user opens the notification drawer

This is the old way of calling notifications but still works…

Page 25: Android  Development

NOTIFICATIONS

o Activity to receive the notification is just a single TextView

Page 26: Android  Development

BREAK

Page 27: Android  Development

RECAP

Installing and Configuring the IDE Java (JDK) Eclipse

Plug-Ins SDKs APIs

The UI screen for Android Applications are called Activities

Intents are used to link Activities There are built-In Intents (Browser, Contacts,

Etc.)

Dialog Windows Toasts Alerts Progress

Notifications

Page 28: Android  Development

USER INTERFACE (ACTIVITIES)

• An Activity is a window that contains the user interface (Views and ViewGroups)

o Views consist ofo TextViews (labels)o TextEdits (text boxs)o Radio Buttonso Check Boxeso Date Pickerso Time Pickerso Etc.

Page 29: Android  Development

USER INTERFACE (ACTIVITIES)

ViewGroups are layouts used to arrange Views into proper location on the screen

o Android supports the following ViewGroups• Linear Layouts• Absolute Layout• Table Layout• Relative Layout• Frame Layout• Scroll View

o ViewGroups can be nested

Page 30: Android  Development

VIEWGROUPS (LINEAR LAYOUT)

o The Linear Layout Stacks Views on top of each other

o Orientation can be Vertical (default) or Horizontal

View

View

View

View

Linear Layout

ViewView

Linear Layout

Page 31: Android  Development

VIEWGROUPS (LINEAR LAYOUT)

Page 32: Android  Development

VIEWGROUPS (RELATIVE LAYOUT)

o The Relative Layout arranges Views in relation to the parent or other Views

Relative Layout

View

View

View

View

View

View

View

Page 33: Android  Development

VIEWGROUPS (RELATIVE LAYOUT)

Page 34: Android  Development

VIEWGROUPS (SCROLLVIEW)

o The ScrollView enables users to scroll through a list of Views that occupy more space than the physical display

o The ScrollView can only have one child, typically a Linear Layout

ScrollViewLinear Layout

View

View

View

View

View

Page 35: Android  Development

VIEWGROUPS (SCROLLVIEW)

Page 36: Android  Development

ANCHORING VIEWS

Page 37: Android  Development

CUSTOM ORIENTATIONS SCREENS

o A preferable alternate to anchoring is to create custom screens based on orientation

o To support Landscape mode, create a new folder in the res folder named layout-land

o Layouts contained in the layout folder defines the UI for portrait mode

o Layouts contained in the layout-land folder defines the UI for landscape mode

Page 38: Android  Development

CUSTOM LANDSCAPE UI

Page 39: Android  Development

PERSISTING STATE INFORMATION

o Changing screen orientation destroys the Activity and re-creates it

o Current state of the Activity is losto When an Activity is killed, it’ll fire the

onPause and onSaveInstanceState eventso You can implement the onPause event to

save state information to database, internal or external storage

Oro Implement the onSaveInstanceState event

and save the state using Bundle objecto After the activity is re-recreated retrieve

and reset the state in the onRestoreInstanceState event

Page 40: Android  Development

PERSISTING STATE INFORMATION

Flow:o Orientation

Changeso Activity is Killedo Activity is re-

createdo State information

“McBean” is lost

Page 41: Android  Development

ACTIVITY LIFE CYCLE

o These are the major events triggered during the life cycle of an Activity

Additionallyo onRestoreInstanceSt

ate occurs after onStart

o onSaveInstanceState occurs after onPause

Page 42: Android  Development

PERSISTING STATE INFORMATION

Page 43: Android  Development

REGISTERING EVENTS FOR VIEWS

o Views can fire events when user interacts with them

o The appropriate events need to be explicitly registered

o Events can be registered using an inner class or an anonymous class

Page 44: Android  Development

REGISTERING EVENTS FOR VIEWS

o Using the AnchorView as an example

o The buttons are linked to the UI buttons using findViewById

o The setOnClickListener gives the buttons “ears” to listen for the click event to be triggered by the user

o btn1…btn4 call an anonymous class btnListener

o Btn5 calls an inner class

Page 45: Android  Development

BASIC VIEWS

Views commonly used are:

TextView – Display InformationEditText – Allows user to key in Information

CheckBox – Turn on and off

RadioButtons – Select one in a list

ToggleButton – Turn on and off

Page 46: Android  Development

SIMPLE LIST VIEWo The ListView displays a long

list of items in an Activityo No UI Layout Requiredo Presentation is dictated by

the second parameter of the setListAdapter

Page 47: Android  Development

CUSTOM LIST VIEWo Colleges array was moved to strings.xml

file and now called as a resource

Page 48: Android  Development

SPINNER VIEWSimilar to the ListView except is used when other Views will be displayed on the UI