Session Presented at 1st IndicThreads.com Conference On Mobile Application Development held on 19-20 November 2010 in Pune, India
WEB: http://M10.IndicThreads.com
------------
Speaker: Rohit Ghatol
Abstract:
This session looks at -
Introduction to Android
Android OS Capabilities
Building Blocks of Android
Use Case – Building Blocks and their Interaction for Gmail Client
Understanding Android UI
Challenges in building Android Application and Best Practices
Web Services Client
Database Vs File Vs Shared Preferences
Minimizing GC
Fetch online Vs Local Cache
Working in Background Threads
Building custom Widgets
2. 2
About Me
Name: Rohit Ghatol
Occupation:
1. Architect @QuickOffice
2. Project Mgr @Synerzip
3. Certified Scrum Master
Thinks I like to do:
1. Talk at Technical Platforms
2. Agile Evangelism
3. Motivational Speaker and Trainer
LinkedIn ProfileLinkedIn Profile
3. 3
Topics
Introduction to Android
Android OS Capabilities
Building Blocks of Android
Understanding HelloWorld
Use Case – Building Blocks in Gmail Client
Understanding Android UI
References & Further Reading
4. 4
Introduction to Android
• Software stack for mobile devices that
includes
• an operating system
• middleware
• key applications
• SDK to develop application
6. 6
Introduction to Android
• About Android Applications
• Written in Java
• Compiled to .dex
• Run in Dalvik VM
• Packaged and Shipped as APK
7. 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. 8
More about Applications
Dalvik VM
Linux Process
Linux Kernel
Process Process Process
Dalvik
VM
Dalvik
VM
Dalvik
VM
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
9. 9
Android Versions
OS
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. 10
Android OS Capabilities
Features
• Phone and OS features
• 3G, GPS, Accelerometer, SQLite, Camera,
Telephony, Webkit, etc
• Reuse of Data
• Reuse of Functionality
11. 11
Android Phone Demo
Before anything you must see what an
Android Phone looks like!
1.Desktop
2.Notification Bar
3.Contact Manager
4.Gmail Application
12. 12
Reuse of Data
Default Contact
Manager
New Contact
Manager
Replaces
What happens to data
feed into the default
Contact Manager?
14. 14
Reuse of Functionality
Sudoko Game New Requirement
Share with Friends using
1.SMS
2.Email
Time to learn SMS API
and Email API and code
them into my application!
More code! Hee hee
15. 15
Reuse of Functionality
Sudoko Game
SMS
Mail
SMS
Mail
Intention: Want
to send Email
Here are two
applications who
can do it for you.
40. 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 …..
45. 45
Building Block – Broadcast Receiver
1. Broadcast Receiver is more of a Call
back
2. Android will call your Broadcast
receiver depending on the intent filter
46. 46
Building Block – Content Provider
1. Content Provider are more of RestFul
like exposed Database
2. They are accessed using Content
Resolver
3. They can allow full CRUD Operations on
them (Any application can
add/delete/edit contacts in Phone’s
Contact Manager)
47. 47
Building Block – Intents
Need
• Class Name
Need
• ACTION
• CATEGORY
• DATA
48. 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. 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. 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
53. 53
Understanding Android UI
• Lets Draw the Screen using Linear Layouts
Current Music Info
Progress Bar
Buttons
Music file 1
Music file 2
Music file 3
Music file 4
54. 54
Understanding Android UI
• Lets Draw the Screen using Linear Layouts
Current Music Info
Progress Bar
Music file 1
Music file 2
Music file 3
Music file 4
Prev NextPlay
56. 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
60. 60
Building Blocks of Android
ActivityActivity ServiceService Broadcast
Receiver
Broadcast
Receiver
Content
Provider/
SQL ite
Database
Content
Provider/
SQL ite
Database
Gmail Sync
Data Store
(Email List)
Data Store
(Email List)
Phone Boots
Communication is using IntentsCommunication is using Intents
62. 62
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
63. 63
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
64. 64
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
starts
65. 65
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
Completes
66. 66
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
Stores
67. 67
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
Stores
Gmail
Notification
68. 68
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
Gmail
Notification
69. 69
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
Gmail
Notification
70. 70
Gmail Sync
ServicePhone Boots
Broadcast R
Data Store
(Email List)
Data Store
(Email List)
Database
Events..
Alarm M..
Phone
Boots
Gmail
Sync
(5 mins)
Activity
Notifi. M..
Gmail
Notification
71. 71
References & Further Reading
1. What is Android?
2. Android Fundamentals
3. Notepad Guided Tutorial
4. Common Tasks?
5. Articles and Docs
6. Best Practices - Performance