84
Getting Started with Android Development Rohit Ghatol

Salt march 2011-getting started with android development

Embed Size (px)

DESCRIPTION

Salt march 2011-getting started with android development

Citation preview

Page 1: Salt march 2011-getting started with android development

Getting Started with Android Development

Rohit Ghatol

Page 2: Salt march 2011-getting started with android development

About MeRohit Ghatol

1. Architect @QuickOffice2. Project Mgr @Synerzip3. Certified Scrum Master4. Author “Beginning PhoneGap” @Apress5. Founder TechNext Pune (Pune Developer

Community)

LinkedIn ProfileLinkedIn Profile

Page 3: Salt march 2011-getting started with android development

Topics

• Understanding Android• Android Building Blocks• Putting Building Blocks Together• Latest things in Android World• Reference Material

3

Page 4: Salt march 2011-getting started with android development

Understanding Android

4

Page 5: Salt march 2011-getting started with android development

What is Android?

• Software stack for mobile devices that includes• an operating system• middleware• key applications• SDK to develop application

5

Page 6: Salt march 2011-getting started with android development

Android Architecture

6

Page 7: Salt march 2011-getting started with android development

Android OS Names

7

Page 8: Salt march 2011-getting started with android development

8

OS Version

Nickname API Level Date

1.1 __ 2 9th February 2009

1.5 Cupcake 3 30 April 2009

1.6 Donut 4 5 September 2009

2.1 Eclair 7 26 October 2009

2.2 Froyo 8 20 May 2010

2.3 Gingerbread 9 6th December 2010

3.0 Honeycomb 11 22nd February 2011

4.X Icecream Sandwich

14 19th October 2011

http://en.wikipedia.org/wiki/Android_version_history

Page 9: Salt march 2011-getting started with android development

Key OS Capabilities

9

Page 10: Salt march 2011-getting started with android development

Android OS Capabilities

• Phone and OS features– 3G/4G,GPS, Accelerometer, Compass, Camera,

SQLite, Wifi, Bluetooth, etc– Near Field Communication– Cloud to Device Messaging (C2DM)– Direct Wifi

Page 11: Salt march 2011-getting started with android development

Android OS Capabilities

• Notable Features of Android– All Applications are equal– Reuse of Data– Reuse of Functionality

Page 12: Salt march 2011-getting started with android development

All Applications are Equal

• Replace Home Application• Replace Contacts, Dialer Applications• Replace SMS, Email Applications• Replace Settings Application• OEM Customizations (e.g HTC Sense)

12

Page 13: Salt march 2011-getting started with android development

Reuse of DataDefault Contact Manager

Replaces

What happens to data feed into the default Contact Manager?

New Contact Manager

Page 14: Salt march 2011-getting started with android development

Reuse of DataDefault Contact Manager

Replaces

New Contact Manager

Content Provider

But Uses

“Replaces” means by default the new app is launched, but old app still exists

Page 15: Salt march 2011-getting started with android development

Reuse of FunctionalityNew RequirementShare with Friends using1.SMS2.Email

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

More code! Hee hee

My CouponsMy Coupons

Page 16: Salt march 2011-getting started with android development

Reuse of FunctionalitySMS

Mail

Intention: Want to send Email

Here are two applications who can do it for you?

My CouponsMy Coupons

Page 17: Salt march 2011-getting started with android development

Reuse of FunctionalitySMS

Mail

My CouponsMy Coupons

Page 18: Salt march 2011-getting started with android development

Reuse of FunctionalitySMS

Mail

My CouponsMy Coupons

Page 19: Salt march 2011-getting started with android development

Android Environment Setup

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

19

Page 20: Salt march 2011-getting started with android development

20

Android SDKAndroid SDKEclipse

ADT

Android …..Android …..

……………….……………….

Android 3.2Android 3.2

Android 4.xAndroid 4.x

Android 2.2Android 2.2

Google API 2.2Google API 2.2

SDK ManagerSDK Manager

AVD ManagerAVD Manager

Manages

Emulator Emulator

Page 21: Salt march 2011-getting started with android development

Android Application

Dex FileDex FileAndroid ManifestAndroid Manifest ResourcesResources

MyApp.apk

Signed by Self Signed Private Key

Page 22: Salt march 2011-getting started with android development

Identity of Android Application

22

Identity Part Example

Package Name com.sparklytix.android.app.twitter

versionCode 1 (numeric value 2,3,4,..101,102)

Private Key

Page 23: Salt march 2011-getting started with android development

Android Build Cycle

23

.java.java .apk.apk.dex.dex.class.class

javac dx

apt

• AndroidManifest.xml• resources• AndroidManifest.xml• resources

Page 24: Salt march 2011-getting started with android development

How Applications behave?

24

Page 25: Salt march 2011-getting started with android development

25

Linux KernelLinux Kernel

Process Process Process

DalvikVM

DalvikVM

DalvikVM

Uid 1Uid 1 Uid 2Uid 2 Uid 3Uid 3 data

data

com.xyz.email

com.abc.skype

com.koko.sukudo

shared_prefs

files

databases

. . . . . .

. . . . . .

UID 1

UID 2

UID 3

Page 26: Salt march 2011-getting started with android development

Android Building Blocks

26

Page 27: Salt march 2011-getting started with android development

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

ActivityActivity ServiceService Broadcast Receiver

Broadcast Receiver

Alarm Manager

Noti-fication

Manager

Content ProviderContent Provider

IntentsIntents

Content Resolver

Building Blocks

Other Components……

Page 28: Salt march 2011-getting started with android development

First Android Application

28

Page 29: Salt march 2011-getting started with android development

29

Page 30: Salt march 2011-getting started with android development

30

Page 31: Salt march 2011-getting started with android development

31

Page 32: Salt march 2011-getting started with android development

32

Page 33: Salt march 2011-getting started with android development

33

Page 34: Salt march 2011-getting started with android development

34

Page 35: Salt march 2011-getting started with android development

Interacting with Buttons

35

Page 36: Salt march 2011-getting started with android development

Interacting with Button

36

Page 37: Salt march 2011-getting started with android development

Interacting with Buttons

37

Page 38: Salt march 2011-getting started with android development

38

Page 39: Salt march 2011-getting started with android development

Screen Navigation

39

Page 40: Salt march 2011-getting started with android development

40

Page 41: Salt march 2011-getting started with android development

41

Page 42: Salt march 2011-getting started with android development

42

Page 43: Salt march 2011-getting started with android development

43

Page 44: Salt march 2011-getting started with android development

44

Page 45: Salt march 2011-getting started with android development

45

Page 46: Salt march 2011-getting started with android development

startActivityForResult()

46

Page 47: Salt march 2011-getting started with android development

47

Page 48: Salt march 2011-getting started with android development

48

Page 49: Salt march 2011-getting started with android development

49

Page 50: Salt march 2011-getting started with android development

50

Page 51: Salt march 2011-getting started with android development

51

Page 52: Salt march 2011-getting started with android development

Intents

52

Page 53: Salt march 2011-getting started with android development

Understanding Intent

Need• Class Name

Need • ACTION• CATEGORY• DATA

Page 54: Salt march 2011-getting started with android development

Program Launcher<?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 55: Salt march 2011-getting started with android development

Conflicts with implicit IntentsSo 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 system that application as the default application hence forth

Page 56: Salt march 2011-getting started with android development

Intent API ReferenceIntent to launch an Activity

• Context.startActivity(intent)

• Context.startActivityForResult(intent)

Intent to launch an Service

• Context.startService(intent)

Intent to send a broadcast

• Context.sendBroadCast(intent)

Page 57: Salt march 2011-getting started with android development

Activity

57

Page 58: Salt march 2011-getting started with android development

Activity Life Cycle

Page 59: Salt march 2011-getting started with android development

ForegroundLifeCycleVisible LifeCycleComplete

LifeCycle

Activity Life Cycle (made easy)

onCreate

onDestroy

onStart

onStop

onResume

onPause

Page 60: Salt march 2011-getting started with android development

What to do in what method?

onCreate

onDestroy

onStart

onStop

onResume

onPause

Page 61: Salt march 2011-getting started with android development

Services

61

Page 62: Salt march 2011-getting started with android development

Calling Service

ActivityActivity

ServiceService

void onStartCommand(Intent intent,…){}

startService(intent)

Fire & ForgetFire & Forget

Page 63: Salt march 2011-getting started with android development

Calling Service

ActivityActivity

ServiceService

1. bindService(intent)2. …..3. service.foo()4. int result=service.bar()

void foo(){}int bar(){}

RPC StyleRPC Style

Page 64: Salt march 2011-getting started with android development

64

Page 65: Salt march 2011-getting started with android development

Broadcast Receivers

65

Page 66: Salt march 2011-getting started with android development

Broadcast ReceiversApp 1App 1

Android OS

App 2App 2

Your AppYour App

Custom Event 1Custom Event 1

Custom Event 2Custom Event 2

Battery Low

Battery Low

RoamingRoamingBootBoot

Network Change

Network Change

Interested in any of these Events.

Page 67: Salt march 2011-getting started with android development

Broadcast Receivers

• No Life Cycle Methods• Only Call back method• 10 second limit before ANR• Need not register with Android Manifest• Can be registered at Runtime

Page 68: Salt march 2011-getting started with android development

Use case Email Application

68

Page 69: Salt march 2011-getting started with android development

Mail Application – Use Case

Page 70: Salt march 2011-getting started with android development

Building Blocks of Android

Activity Service BroadcastReceiver

Content Provider/

SQL ite Database

Mail SyncData Store(Email List)Data Store(Email List)

Phone Boots

Communication is using Intents

Page 71: Salt march 2011-getting started with android development

Activity

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Notifi. M..

Phone Boots

Page 72: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Page 73: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Broadcast R

Page 74: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Broadcast R

Page 75: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

starts

Page 76: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Completes

Page 77: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Stores

Page 78: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Stores

Mail Notification

Page 79: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Mail Notification

Page 80: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Mail Notification

Data Store(Email List)Data Store(Email List)

Database

Page 81: Salt march 2011-getting started with android development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots

MailSync (5 mins)

Activity

Notifi. M..

Mail Notification

Page 82: Salt march 2011-getting started with android development

Twitter App

• All these Building blocks are covered in more detail on 3rd November at 3:40 p.m in “Building Twitter App for Android”

82

Page 83: Salt march 2011-getting started with android development

Q & A

83

Page 84: Salt march 2011-getting started with android development

More about Me• Twitter - http://twitter.com/#!/rohitghatol • TechGig -

http://www.techgig.com/rohitghatol • LinkedIn -

http://www.linkedin.com/in/rohitghatol• Presentations -

www.slideshare.net/rohitsghatol/ • YouTube Tutorials -

http://www.youtube.com/user/rohitssghatol