Top Banner
Getting Started with Android Development Rohit Ghatol
84

Getting Started with Android Development

Feb 14, 2016

Download

Documents

thy

Getting Started with Android Development. Rohit Ghatol. About Me. Rohit Ghatol Architect @QuickOffice Project Mgr @Synerzip Certified Scrum Master Author “ Beginning PhoneGap ” @Apress Founder TechNext Pune (Pune Developer Community). LinkedIn Profile. Topics. Understanding Android - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with Android Development

Getting Started with Android Development

Rohit Ghatol

Page 2: 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: 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: Getting Started with Android Development

Understanding Android

4

Page 5: 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: Getting Started with Android Development

Android Architecture

6

Page 7: Getting Started with Android Development

Android OS Names

7

Page 8: 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: Getting Started with Android Development

Key OS Capabilities

9

Page 10: 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: Getting Started with Android Development

Android OS Capabilities

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

Page 12: 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: 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: 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: 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 Coupons

Page 16: 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 Coupons

Page 17: Getting Started with Android Development

Reuse of FunctionalitySMS

Mail

My Coupons

Page 18: Getting Started with Android Development

Reuse of FunctionalitySMS

Mail

My Coupons

Page 19: Getting Started with Android Development

Android Environment Setup

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

19

Page 20: Getting Started with Android Development

20

Android SDKEclipse

ADT

Android …..

……………….

Android 3.2

Android 4.x

Android 2.2

Google API 2.2

SDK Manager

AVD Manager

Manages

Emulator Emulator

Page 21: Getting Started with Android Development

Android Application

Dex FileAndroid Manifest Resources

MyApp.apk

Signed by Self Signed Private Key

Page 22: 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: Getting Started with Android Development

Android Build Cycle

23

.java .apk.dex.class

javac dx

apt

• AndroidManifest.xml• resources

Page 24: Getting Started with Android Development

How Applications behave?

24

Page 25: Getting Started with Android Development

25

Linux Kernel

Process Process Process

DalvikVM

DalvikVM

DalvikVM

Uid 1 Uid 2 Uid 3 data

data

com.xyz.email

com.abc.skype

com.koko.sukudo

shared_prefs

files

databases

. . . . . .

. . . . . .

UID 1

UID 2

UID 3

Page 26: Getting Started with Android Development

Android Building Blocks

26

Page 27: Getting Started with Android Development

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

Activity Service Broadcast Receiver

Alarm Manager

Noti-fication

Manager

Content Provider

Intents

Content Resolver

Building Blocks

Other Components……

Page 28: Getting Started with Android Development

First Android Application

28

Page 29: Getting Started with Android Development

29

Page 30: Getting Started with Android Development

30

Page 31: Getting Started with Android Development

31

Page 32: Getting Started with Android Development

32

Page 33: Getting Started with Android Development

33

Page 34: Getting Started with Android Development

34

Page 35: Getting Started with Android Development

Interacting with Buttons

35

Page 36: Getting Started with Android Development

Interacting with Button

36

Page 37: Getting Started with Android Development

Interacting with Buttons

37

Page 38: Getting Started with Android Development

38

Page 39: Getting Started with Android Development

Screen Navigation

39

Page 40: Getting Started with Android Development

40

Page 41: Getting Started with Android Development

41

Page 42: Getting Started with Android Development

42

Page 43: Getting Started with Android Development

43

Page 44: Getting Started with Android Development

44

Page 45: Getting Started with Android Development

45

Page 46: Getting Started with Android Development

startActivityForResult()

46

Page 47: Getting Started with Android Development

47

Page 48: Getting Started with Android Development

48

Page 49: Getting Started with Android Development

49

Page 50: Getting Started with Android Development

50

Page 51: Getting Started with Android Development

51

Page 52: Getting Started with Android Development

Intents

52

Page 53: Getting Started with Android Development

Understanding Intent

Need• Class Name

Need • ACTION• CATEGORY• DATA

Page 54: 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: 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: 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: Getting Started with Android Development

Activity

57

Page 58: Getting Started with Android Development

Activity Life Cycle

Page 59: Getting Started with Android Development

ForegroundLifeCycleVisible LifeCycleComplete

LifeCycle

Activity Life Cycle (made easy)

onCreate

onDestroy

onStart

onStop

onResume

onPause

Page 60: Getting Started with Android Development

What to do in what method?

onCreate

onDestroy

onStart

onStop

onResume

onPause

Page 61: Getting Started with Android Development

Services

61

Page 62: Getting Started with Android Development

Calling Service

Activity

Service

void onStartCommand(Intent intent,…){}

startService(intent)

Fire & Forget

Page 63: Getting Started with Android Development

Calling Service

Activity

Service

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

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

RPC Style

Page 64: Getting Started with Android Development

64

Page 65: Getting Started with Android Development

Broadcast Receivers

65

Page 66: Getting Started with Android Development

Broadcast ReceiversApp 1

Android OS

App 2

Your App

Custom Event 1

Custom Event 2

Battery Low

RoamingBoot

Network Change

Interested in any of these Events.

Page 67: 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: Getting Started with Android Development

Use case Email Application

68

Page 69: Getting Started with Android Development

Mail Application – Use Case

Page 70: Getting Started with Android Development

Building Blocks of Android

Activity Service BroadcastReceiver

Content Provider/

SQL ite Database

Mail Sync Data Store(Email List)

Phone Boots

Communication is using Intents

Page 71: Getting Started with Android Development

Activity

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..Notifi. M..

Phone Boots

Page 72: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Page 73: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Broadcast R

Page 74: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Broadcast R

Page 75: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

starts

Page 76: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Completes

Page 77: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Stores

Page 78: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Stores

Mail Notification

Page 79: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Mail Notification

Page 80: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Mail Notification

Data Store(Email List)

Database

Page 81: Getting Started with Android Development

Mail Sync

ServicePhone Boots

Broadcast R

Data Store(Email List)

Database

Events..

Alarm M..

Phone Boots Mail

Sync (5 mins)

Activity

Notifi. M..

Mail Notification

Page 82: 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: Getting Started with Android Development

Q & A

83

Page 84: 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