salt march 2011-getting started with android development

Post on 17-May-2015

204 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Salt march 2011-getting started with android development

TRANSCRIPT

Getting Started with Android Development

Rohit Ghatol

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

Topics

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

3

Understanding Android

4

What is Android?

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

5

Android Architecture

6

Android OS Names

7

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

Key OS Capabilities

9

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

Android OS Capabilities

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

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

Reuse of DataDefault Contact Manager

Replaces

What happens to data feed into the default Contact Manager?

New Contact Manager

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

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

Reuse of FunctionalitySMS

Mail

Intention: Want to send Email

Here are two applications who can do it for you?

My CouponsMy Coupons

Reuse of FunctionalitySMS

Mail

My CouponsMy Coupons

Reuse of FunctionalitySMS

Mail

My CouponsMy Coupons

Android Environment Setup

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

19

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

Android Application

Dex FileDex FileAndroid ManifestAndroid Manifest ResourcesResources

MyApp.apk

Signed by Self Signed Private Key

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

Android Build Cycle

23

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

javac dx

apt

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

How Applications behave?

24

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

Android Building Blocks

26

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

First Android Application

28

29

30

31

32

33

34

Interacting with Buttons

35

Interacting with Button

36

Interacting with Buttons

37

38

Screen Navigation

39

40

41

42

43

44

45

startActivityForResult()

46

47

48

49

50

51

Intents

52

Understanding Intent

Need• Class Name

Need • ACTION• CATEGORY• DATA

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

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

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)

Activity

57

Activity Life Cycle

ForegroundLifeCycleVisible LifeCycleComplete

LifeCycle

Activity Life Cycle (made easy)

onCreate

onDestroy

onStart

onStop

onResume

onPause

What to do in what method?

onCreate

onDestroy

onStart

onStop

onResume

onPause

Services

61

Calling Service

ActivityActivity

ServiceService

void onStartCommand(Intent intent,…){}

startService(intent)

Fire & ForgetFire & Forget

Calling Service

ActivityActivity

ServiceService

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

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

RPC StyleRPC Style

64

Broadcast Receivers

65

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.

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

Use case Email Application

68

Mail Application – Use Case

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

Activity

Mail Sync

ServicePhone Boots

Broadcast R

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

Database

Events..

Alarm M..

Notifi. M..

Phone Boots

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

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

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

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

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

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

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

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

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

Q & A

83

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

top related