Android101 - Intro and Basics

31
Android 101 Part 1. Introduction, basics, and your environment

Transcript of Android101 - Intro and Basics

Page 1: Android101 - Intro and Basics

Android 101Part 1. Introduction, basics,

and your environment

Page 2: Android101 - Intro and Basics

While we wait…

Android ADT Bundle

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

ml

Genymotion

http://www.genymotion.com/

Page 3: Android101 - Intro and Basics

Prerequisites

OOP Language Experience

Computer (Mac/Linux/Windows)

Plus:

Java – programming

XML – layouts and resources

Command Line – general commands

Page 4: Android101 - Intro and Basics

What is Android?

Platform

The operating system

Framework

Set of APIs to develop for the platform

SDK

Set of tools (including the framework) to

assist developing for the platform

Page 5: Android101 - Intro and Basics

Source: http://www.armdesigner.com/NewsLook617.html

Page 6: Android101 - Intro and Basics

Android and Google

Android is open source (AOSP)

Google is the owner/maintainer

Source: http://source.android.com

GApps

Google specific closed source apps

Google Play Store

Google Play Services

Google Maps

Page 7: Android101 - Intro and Basics

Uses for Android?

Calls

Music

Videos

Games

Social

Educational

Commercial (POS)

Satellite

Security

Accessory

Page 8: Android101 - Intro and Basics

Android vs iOS

Open Source

Java / XML

78.4% MS Worldwide

50.6% MS USA

$100-$200/month

800,000 apps

~$130,000 senior dev

Closed Source

Objective-C

17.6% MS Worldwide

43.9% MS USA

$500-$1000/month

800,000 apps

~$120,000 senior dev

Page 9: Android101 - Intro and Basics

Versions (OS vs API)

Page 10: Android101 - Intro and Basics

ComponentsIn context of our demo

application

Page 11: Android101 - Intro and Basics

Demo Application

Features:

Displays lists of saved notes

Allows user to add and edit notes

Can record notes

Can playback notes

Stops recording or playback when a call is

incoming or made

Page 12: Android101 - Intro and Basics

Step 1: DisplayWe need to display a few screens to the user…

Page 13: Android101 - Intro and Basics

Activities

Represents a single screen

extends Activity class

Page 14: Android101 - Intro and Basics

Fragments

Represents a section of the screen

An Activity coordinates the Fragment(s)

Fragments can be reused

extends Fragment class

Page 15: Android101 - Intro and Basics

Step 2: Persist DataWe need to persist the notes the user adds…

Page 16: Android101 - Intro and Basics

ContentProvider

Manages data

Can use almost any storage option

SQLite

File

Remote Server

Provides consistent interface (CRUD)

Can be restricted with permissions

extends ContentProvider class

Page 17: Android101 - Intro and Basics

Step 3: Record/Play

AudioWe need to record or play audio while allowing for

multitasking…

Page 18: Android101 - Intro and Basics

Services

Used to perform in the background

Service class works in main thread

IntentService (child class) works in

background thread

Background = No user interface

extends Service class

Page 19: Android101 - Intro and Basics

Step 4: Phone stateWe need to stop/pause audio playback or

recording…

Page 20: Android101 - Intro and Basics

BroadcastRecievers

Listens to system-wide events

Incoming SMS

Alarm

Network State

Usually triggers a larger action

extends BroadcastReciever class

Page 21: Android101 - Intro and Basics

Using the

Components

Page 22: Android101 - Intro and Basics

AndroidManifest.xml Declares: Permissions used

Libraries required

Hardware required

Package name (must be unique)

Application name

Components Activity <activity>

Service <service> ContentProvider <provider> BroadcastReciever <reciever>

Page 23: Android101 - Intro and Basics

Intents (options) Component Name

The name of the component to start

Action Examples: VIEW, EDIT, PICK

Data Uri to the data

Examples: Image, URL, Document

Category Examples: Browsable, Launcher

Extras Key-value pairs of data to pass to the component

Flags Used to tell the Android system how to launch certain

components

extends Intent class

Page 24: Android101 - Intro and Basics

IntentFilters action

name android.intent.action.SEND

com.example.whatever.DO_IT

data mimeType scheme host port path …

category BROWSABLE LAUNCHER DEFAULT

Page 25: Android101 - Intro and Basics

Intents Explicit Intent

Intent to start a specific component you know exists, such as from your app or a system component

new Intent(this, SecondActivity.class)

Implicit Intent

Intent to do a general action and possibly allow other applications to handle it

new Intent(Intent.ACTION_VIEW,

Uri.parse(“http://google.com”))

extends Intent class

Page 26: Android101 - Intro and Basics

ResourcesA very quick glimpse

Page 27: Android101 - Intro and Basics

Resources

animator

anim

color

drawable

layout

menu raw

values arrays

colors dimens strings styles

xml

res/ directory

Page 28: Android101 - Intro and Basics

Resources (qualifiers)

Language and region

Layout direction Smallest Width Available Width Available Height Screen size Screen Aspect

Screen Orientation UI Mode Screen Pixel Density Platform Version …

res/ directory

Page 29: Android101 - Intro and Basics

EnvironmentSetting it up

Page 30: Android101 - Intro and Basics

Environment - Java JDK

Java 7 JDK - http://goo.gl/zXjC

To confirm:

… run: javac –version

… output: javac 1.7.0_45

Page 31: Android101 - Intro and Basics

Environment - ADT Bundle

ADT Bundle - http://goo.gl/2qpr

Eclipse + ADT Plugin

Android SDK Tools

Android Platform Tools

Latest Android platform

Latest Android System image