Indic thread 2010-android-basics

73
1 Android Basics Rohit Ghatol QuickOffice & Synerzip

Transcript of Indic thread 2010-android-basics

Page 1: Indic thread 2010-android-basics

1

Android Basics Rohit GhatolQuickOffice & Synerzip

Page 2: Indic thread 2010-android-basics

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

Page 3: Indic thread 2010-android-basics

3

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

Page 4: Indic thread 2010-android-basics

4

Introduction to Android• Software stack for mobile devices

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

Page 5: Indic thread 2010-android-basics

5

Introduction to Android

Page 6: Indic thread 2010-android-basics

6

Introduction to Android• About Android Applications

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

Page 7: Indic thread 2010-android-basics

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

Page 8: Indic thread 2010-android-basics

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

Page 9: Indic thread 2010-android-basics

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

Page 10: Indic thread 2010-android-basics

10

Android OS CapabilitiesFeatures• Phone and OS features

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

• Reuse of Data• Reuse of Functionality

Page 11: Indic thread 2010-android-basics

11

Android Phone DemoBefore anything you must see what an Android

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

Page 12: Indic thread 2010-android-basics

12

Reuse of DataDefault Contact

ManagerNew Contact

Manager

Replaces

What happens to data feed into the default Contact Manager?

Page 13: Indic thread 2010-android-basics

13

Reuse of DataDefault Contact

ManagerNew Contact

Manager

Replaces

Content Provider

But Uses

Page 14: Indic thread 2010-android-basics

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

Page 15: Indic thread 2010-android-basics

15

Reuse of FunctionalitySudoko Game

SMS

Mail

SMS

Mail

Intention: Want to send Email

Here are two applications who can do it for you.

Page 16: Indic thread 2010-android-basics

16

Reuse of FunctionalitySudoko Game

SMS

Mail

SMS

Mail

Intention: Want to send Email

Page 17: Indic thread 2010-android-basics

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

Page 18: Indic thread 2010-android-basics

18

Environment Setup

Page 19: Indic thread 2010-android-basics

19

Environment Setup

Page 20: Indic thread 2010-android-basics

20

Environment Setup

Text

Page 21: Indic thread 2010-android-basics

21

Text

Environment Setup

Page 22: Indic thread 2010-android-basics

22

Simple HelloWorld

Text

Page 23: Indic thread 2010-android-basics

23

Simple HelloWorld

Text

Page 24: Indic thread 2010-android-basics

24

Simple HelloWorld

Text

Page 25: Indic thread 2010-android-basics

25

Simple HelloWorld

Text

Page 26: Indic thread 2010-android-basics

26

Simple HelloWorld

Text

Page 27: Indic thread 2010-android-basics

27

Simple HelloWorld

Text

Page 28: Indic thread 2010-android-basics

28

Simple HelloWorld

Text

Page 29: Indic thread 2010-android-basics

29

Simple HelloWorld

Text

Page 30: Indic thread 2010-android-basics

30

Simple HelloWorld

Text

Page 31: Indic thread 2010-android-basics

31

Simple HelloWorld

Text

Page 32: Indic thread 2010-android-basics

32

Simple HelloWorld

Text

Page 33: Indic thread 2010-android-basics

33

Simple HelloWorld

Text

Page 34: Indic thread 2010-android-basics

34

Simple HelloWorld

Text

Page 35: Indic thread 2010-android-basics

35

Simple HelloWorld

Text

Page 36: Indic thread 2010-android-basics

36

Simple HelloWorld

Text

Page 37: Indic thread 2010-android-basics

37

Simple HelloWorld

Text

Page 38: Indic thread 2010-android-basics

38

Simple HelloWorld

Text

Page 39: Indic thread 2010-android-basics

39

Simple HelloWorld

Text

Page 40: Indic thread 2010-android-basics

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 …..

Page 41: Indic thread 2010-android-basics

41

Building Block - Activity

Activity Life Cycle

Page 42: Indic thread 2010-android-basics

42

ForegroundLifeCycleVisible

LifeCycleComplete LifeCycle

Building Block - Activity

Activity Life Cycle made easieronCreate

onDestroy

onStart

onStop

onResume

onPause

Page 43: Indic thread 2010-android-basics

43

Building Block - Activity

What to do in each life cycle methods?onCreate

onDestroy

onStart

onStop

onResume

onPause

Page 44: Indic thread 2010-android-basics

44

Building Block - Service

ServiceLifeCycle

Page 45: Indic thread 2010-android-basics

45

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

back2. Android will call your Broadcast

receiver depending on the intent filter

Page 46: Indic thread 2010-android-basics

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)

Page 47: Indic thread 2010-android-basics

47

Building Block – Intents

Need• Class Name

Need • ACTION• CATEGORY• DATA

Page 48: Indic thread 2010-android-basics

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

Page 49: Indic thread 2010-android-basics

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

Page 50: Indic thread 2010-android-basics

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

Page 51: Indic thread 2010-android-basics

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>

Page 52: Indic thread 2010-android-basics

52

Understanding Android UI

• Lets Draw the Screen using Linear Layouts

Current Playlist

Player

Page 53: Indic thread 2010-android-basics

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

Page 54: Indic thread 2010-android-basics

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

Page 55: Indic thread 2010-android-basics

55

Layout XML

………………………….

………………………….

Page 56: Indic thread 2010-android-basics

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

Page 57: Indic thread 2010-android-basics

57

Layout XML

Page 58: Indic thread 2010-android-basics

58

Understanding Android UI

Use LayoutsLayouts can be defined in different XML

filesCode can refer to these layout xml files

Page 59: Indic thread 2010-android-basics

59

Gmail Application – Use Case

Page 60: Indic thread 2010-android-basics

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

Page 61: Indic thread 2010-android-basics

61

Activity

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Notifi. M..

Phone Boots

Page 62: Indic thread 2010-android-basics

62

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Page 63: Indic thread 2010-android-basics

63

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Page 64: Indic thread 2010-android-basics

64

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

starts

Page 65: Indic thread 2010-android-basics

65

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Completes

Page 66: Indic thread 2010-android-basics

66

Gmail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

GmailSync (5 mins)

Activity

Notifi. M..

Stores

Page 67: Indic thread 2010-android-basics

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

Page 68: Indic thread 2010-android-basics

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

Page 69: Indic thread 2010-android-basics

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

Page 70: Indic thread 2010-android-basics

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

Page 71: Indic thread 2010-android-basics

71

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

Page 72: Indic thread 2010-android-basics

72

Youtube Videos - Android

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

Page 73: Indic thread 2010-android-basics

73

Reach Me1. Linked In2. Email – [email protected]