Indic thread 2010-android-basics

Preview:

Citation preview

1

Android Basics Rohit GhatolQuickOffice & Synerzip

2

About MeName: Rohit GhatolOccupation:

1. Architect @QuickOffice2. Project Mgr @Synerzip3. Certified Scrum Master

Thinks I like to do:1. Talk at Technical Platforms2. Agile Evangelism3. Motivational Speaker and Trainer

LinkedIn ProfileLinkedIn Profile

3

TopicsIntroduction to AndroidAndroid OS CapabilitiesBuilding Blocks of AndroidUnderstanding HelloWorldUse Case – Building Blocks in Gmail ClientUnderstanding Android UIReferences & Further Reading

4

Introduction to Android• Software stack for mobile devices

that includes• an operating system• middleware• key applications• SDK to develop application

5

Introduction to Android

6

Introduction to Android• About Android Applications

• Written in Java• Compiled to .dex • Run in Dalvik VM• Packaged and Shipped as APK

7

Introduction to Android• About Dalvik VM

• Cut from Apache Harmony Project• Device can run multiple VMs efficiently• Executes Dalvik Executable (.dex) -

optimized for minimal memory footprint• Watch Video – Dalvik VM Internals

8

More about Applications

Dalvik VM

Linux Process

Linux Kernel

Process Process Process

DalvikVM

DalvikVM

DalvikVM

Uid 1 Uid 2 Uid 3data

data

com.xyz.email

com.abc.skype

com.koko.sukudo

shared_prefs

files

databases

. . . . . .

. . . . . .

UID 1

UID 2

UID 3

9

Android VersionsOS Version

Nickname API Level Date Comments

1.1 __ 2 February 2009

1.5 Cupcake 3 30 April 2009 Based on Linux Kernel 2.6.27

1.6 Donut 4 5 September 2009

Based on Linux Kernel 2.6.29

2.1 Eclair 7 26 October 2009 

Based on Linux Kernel 2.6.29

2.2  Froyo 8 20 May 2010 Based on Linux Kernel 2.6.32

2.3 Gingerbread Q4 20103.0 Based on Linux Kernel 2.6.33 or .34

3.0 Honeycomb early 2011

10

Android OS CapabilitiesFeatures• Phone and OS features

• 3G, GPS, Accelerometer, SQLite, Camera, Telephony, Webkit, etc

• Reuse of Data• Reuse of Functionality

11

Android Phone DemoBefore anything you must see what an Android

Phone looks like!1.Desktop2.Notification Bar3.Contact Manager4.Gmail Application

12

Reuse of DataDefault Contact

ManagerNew Contact

Manager

Replaces

What happens to data feed into the default Contact Manager?

13

Reuse of DataDefault Contact

ManagerNew Contact

Manager

Replaces

Content Provider

But Uses

14

Reuse of FunctionalitySudoko Game New Requirement

Share with Friends using1.SMS2.Email

Time to learn SMS API and Email API and code them into my application!

More code! Hee hee

15

Reuse of FunctionalitySudoko Game

SMS

Mail

SMS

Mail

Intention: Want to send Email

Here are two applications who can do it for you.

16

Reuse of FunctionalitySudoko Game

SMS

Mail

SMS

Mail

Intention: Want to send Email

17

Building Blocks of Android

Activity(Screen)

Service(Background)

BroadcastReceiver

(respond to events)

Content Provider

(Database/Directory)

Notification Manager

......

Alarm Manager

Read more - http://developer.android.com/guide/topics/fundamentals.html

18

Environment Setup

19

Environment Setup

20

Environment Setup

Text

21

Text

Environment Setup

22

Simple HelloWorld

Text

23

Simple HelloWorld

Text

24

Simple HelloWorld

Text

25

Simple HelloWorld

Text

26

Simple HelloWorld

Text

27

Simple HelloWorld

Text

28

Simple HelloWorld

Text

29

Simple HelloWorld

Text

30

Simple HelloWorld

Text

31

Simple HelloWorld

Text

32

Simple HelloWorld

Text

33

Simple HelloWorld

Text

34

Simple HelloWorld

Text

35

Simple HelloWorld

Text

36

Simple HelloWorld

Text

37

Simple HelloWorld

Text

38

Simple HelloWorld

Text

39

Simple HelloWorld

Text

40

Building Application .

You need a Screen (Activity)Views could be• Buttons• Text Views• etc ….

Layouts could be• Linear Layout• Relative Layout• Table Layout• etc …..

41

Building Block - Activity

Activity Life Cycle

42

ForegroundLifeCycleVisible

LifeCycleComplete LifeCycle

Building Block - Activity

Activity Life Cycle made easieronCreate

onDestroy

onStart

onStop

onResume

onPause

43

Building Block - Activity

What to do in each life cycle methods?onCreate

onDestroy

onStart

onStop

onResume

onPause

44

Building Block - Service

ServiceLifeCycle

45

Building Block – Broadcast Receiver1. Broadcast Receiver is more of a Call

back2. Android will call your Broadcast

receiver depending on the intent filter

46

Building Block – Content Provider1. Content Provider are more of RestFul

like exposed Database2. They are accessed using Content

Resolver3. They can allow full CRUD Operations

on them (Any application can add/delete/edit contacts in Phone’s Contact Manager)

47

Building Block – Intents

Need• Class Name

Need • ACTION• CATEGORY• DATA

48

Building Block – Intents<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sample“ android:versionCode="1“ android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloWorld" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="4" /></manifest>

Program launcher shows all the activities which have MAIN Action and LAUNCHER category

49

Building Application .So what happens two activities have the exact same intent filter and an intent is fired.

Simple you choose one application, and you have an option to tell to se that application as the default application hence forth

50

Building Application .

Intent to launch an Activity

• Context.startActivity(intent)

• ContextstartActivityForResult(intent)

Intent to launch an Service

• Context.startService(intent)

Intent to send a broadcast

• Context.sendBroadCast(intent)

Using Intents

51

Building Block – Permissions<manifest

xmlns:android="http://schemas.android.com/apk/res/android package="com.android.app.myapp" > ……………………………………………………………..<uses-permission android:name="android.permission.RECEIVE_SMS" />

</manifest>

52

Understanding Android UI

• Lets Draw the Screen using Linear Layouts

Current Playlist

Player

53

Understanding Android UI

• Lets Draw the Screen using Linear Layouts

Current Music InfoProgress Bar

Buttons

Music file 1

Music file 2

Music file 3

Music file 4

54

Understanding Android UI

• Lets Draw the Screen using Linear Layouts

Current Music InfoProgress Bar

Music file 1

Music file 2

Music file 3

Music file 4

Prev NextPlay

55

Layout XML

………………………….

………………………….

56

Understanding Android UI

• Lets Draw the Screen using Relative Layouts

Beautiful World

Take That

Title is aligned to the top and right of the image

Author is aligned to the bottom and right of the

image

57

Layout XML

58

Understanding Android UI

Use LayoutsLayouts can be defined in different XML

filesCode can refer to these layout xml files

59

Gmail Application – Use Case

60

Building Blocks of Android

Activity Service BroadcastReceiver

Content Provider/SQL ite

Database

Gmail Sync Data Store(Email List)

Phone Boots

Communication is using Intents

61

Activity

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Notifi. M..

Phone Boots

62

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

63

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

64

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

starts

65

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Completes

66

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Stores

67

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Stores

Gmail Notification

68

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Gmail Notification

69

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Gmail Notification

70

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Gmail Notification

71

References & Further Reading1. What is Android?2. Android Fundamentals3. Notepad Guided Tutorial4. Common Tasks?5. Articles and Docs6. Best Practices - Performance

72

Youtube Videos - Android

http://www.youtube.com/user/GoogleDevelopers#g/c/316B437F0CB82A68

73

Reach Me1. Linked In2. Email – rohitsghatol@gmail.com

Recommended