SlideShare a Scribd company logo
INTRODUCTIONTO
ANDROID DEVELOPMENT
Jim McKeeth
@JimMcKeeth
jim@mckeeth.org
1
Tuesday, August 20, 13
AGENDA
• Hello Android
• Overview of Platform
• PlatformTools
• UI - XML
• Views & Widgets
• Architecture
• Manifest & Permission
• Activities & Intents
• Debugging
• Resources
2
Tuesday, August 20, 13
ABOUT ME
• Live here in Boise - jim@mckeeth.org
• Lead Developer Evangelist for EmbarcaderoTechnologies
• www.embarcadero.com - Delphi for Android coming soon
• Google Developer Group - www.gdgb.org
• Boise Software Developers Group - www.bsdg.org
• Boise Code Camp - www.BoiseCodeCamp.com
Tuesday, August 20, 13
DEMO: HELLO ANDROID
Tuesday, August 20, 13
GOOD PLACESTO KNOW
• developer.android.com - Official developer site
• developers.google.com/android/ - Google on Android
• developers.google.com/events/io/ - Google I/O Replays
• stackoverflow.com - Great Q&A community
• android.stackexchange.com - End user Q&A
• vogella.com/android.html - Detailed tutorials
5
Tuesday, August 20, 13
ANDROID
6
Tuesday, August 20, 13
ANDROID STACK
• Tweaked Linux 2.6
• Tweaked Java (Dalvik)
• Android OS
• Android Apps
• (Mostly open source)
7
Tuesday, August 20, 13
VERSION HISTORY
• November 5th, 2007 is Android’s Birthday
• Each version has a version number, name and API level
• Version number is most specific
• Name is group of versions and API levels
• Latest:Android 4.3 Jelly Bean (API 18)
http://en.wikipedia.org/wiki/Android_version_history#Version_history_by_API_level
Tuesday, August 20, 13
VERSION POPULARITY
As of August 2013
http://sn.im/platform-versions9
40% = Jelly Bean
63% >= ICS
96% >= Gingerbread
40%
23%
33%
Tuesday, August 20, 13
Tuesday, August 20, 13
ARCHITECTURE
http://sn.im/what-is-android
11
Tuesday, August 20, 13
FRAMEWORK
• DalvikVM
• WebKit Browser
• 2d Graphics Library, 3D w/OpenGL
• SQLite
• MPEG4, MP3, PNG, JPEG, etc
• GSMTelephony, Bluetooth,WiFi
• Camera, GPS, Compass,Accelerometer
12
Tuesday, August 20, 13
CORE APPLICATIONS
• Phone
• eMail and SMS clients
• Calendar
• Contacts
• Web Browser
• Geographic Support via Google Maps
13
Tuesday, August 20, 13
ANDROID DEVELOPMENT
Tuesday, August 20, 13
ANDROID SDK
• http://developer.android.com/sdk
• 3 Options
• ADT Bundle (in Eclipse)
• ā€œExisting IDEā€ download
• Android Studio preview (in IntelliJ)
15
Tuesday, August 20, 13
RELATEDTOOLS
• Managers
• Android SDK Manager
• AVD Manager (AndroidVirtual Device)
• Command-LineTools
• adb (Android Debug Bridge -Your best friend!)
• Others
Tuesday, August 20, 13
ANDROID DEVELOPMENT
JDK$
Android'
SDK'
Dalvik'
Virtual'
Machine'
Linux&
kernel&
Tuesday, August 20, 13
BUILD PROCESS
Android'App'Package'
APK'
DEX'Compiler'
Dalvik'byte'code'
Java'Compiler'
Java'JAR'
Tuesday, August 20, 13
THE APK FILE
• Zip file containing
• Manifest, etc.
• Compiled code
• Resources & Assets
Tuesday, August 20, 13
ACTIVITY ARCHITECTURE
Tuesday, August 20, 13
Applica'on*Context*
PARTS OF AN ANDROID APP
Intent%
Ac#vity(
Class% Layout' String'
Resources'
Android'
Manifest'
Other&
Classes&
Drawables)
Services(
Broadcast)
Receiver)
Content&
Providers&
Ac#vity( Intent%
Tuesday, August 20, 13
PROJECT LAYOUT
• AndroidManifest.xml
• bin (APK file, compiled DEX files)
• gen (generated resources)
• res (resources you create)
• src (Java source files)
Tuesday, August 20, 13
MANIFEST
• Mandatory XML file ā€œAndroidManifest.xmlā€
• Describe application components
• Default Activity
• Permissions,Attributes
• Non-SDK libraries
http://sn.im/android-manifest
Tuesday, August 20, 13
MULTIPLE ACTIVITIES
• Each Activity must be defined in manifest by class name and
ā€œactionā€
• Activities reside on a ā€œtask stackā€ - visible activity is ā€œtop of
stackā€
• Transition to an Activity using Intent
• Return from Activity using Activity.finish() which pops off task
stack
Tuesday, August 20, 13
ā€œRESā€ - RESOURCES
• XML Files
• drawable
• layout
• values
• etc.
• Graphics
Tuesday, August 20, 13
RES/LAYOUT
• Each Activity should have dedicated layout XML file
• Layout file specifies Activity appearance
• Several layout types
• Default LinearLayout provides sequential placement of widgets
Tuesday, August 20, 13
RES/VALUES
• strings.xml contains String constants
• Prefer strings.xml to hardcoded values (warnings)
• L10N/I18N (Localization/Internationalization)
Tuesday, August 20, 13
• Application/Task is a stack of Activities
• Visible activity = top of stack
• Activities maintain state, even when notTOS
• ā€œBackā€ button pops stack.
• ā€œHomeā€ key would move stack to background
• Selecting application brings to foreground or launches
new instance
APPLICATION AKATASK
Tuesday, August 20, 13
ANDROID.APP.ACTIVITY
• Activity extends Context
• Context contains application environment
• ā€œa single focused thing a user can doā€
• An application consists of 1 or more Activities
• Provides a default window to draw in, might be smaller than
screen or float on top of others
• UI elements are ā€œView(s)ā€ or widgets
Tuesday, August 20, 13
ANDROID.VIEW.VIEW
• Extends java.lang.Object
• Basic building block for UI components
• Rectangular area on display
• Responsible for drawing and event handling
• View is the base class for widgets
Tuesday, August 20, 13
Callback Methods
(delegates)
Major States
Activity
Lifecycle
http://sn.im/android-activity
Tuesday, August 20, 13
SAVING STATE
Tuesday, August 20, 13
FRAGMENTS
http://sn.im/android-fragments
Tuesday, August 20, 13
ANDROID.CONTENT.INTENT
• Interprocess Communication messaging
• Can launch an Activity or start a Service
• new Intent(String action, Uri uri);
• new Intent(Context packageCtx, Class class);
• Intent.putExtra()
• Intent.setAction()
http://sn.im/android-intent
Tuesday, August 20, 13
INTENT (CONTINUED)
• android.intent.action.MAIN (receiver on main activity)
• many options:ACTION_VIEW, etc
• category = extra information
• MIME type
• extras (i.e. getAction(), getExtra(), etc)
Tuesday, August 20, 13
INTENT USAGE
• Activity Switch:
• new Intent(this, NextActivity.class);
• Web Browser:
• Uri uri = Uri.parse(ā€œhttp://foobar.comā€);
• new Intent(Intent.ACTION_VIEW, uri);
• Phone Dialer:
• Uri uri = Uri.parse(ā€œtel:4085551212ā€);
• new Intent(Intent.ACTION_VIEW, uri);
http://sn.im/android-intent
Tuesday, August 20, 13
VIEWS
Tuesday, August 20, 13
VIEW LISTENERS
• GUI is event driven
• Event source: button press, mouse click, etc.
• Listener catches event and performs action
• Events are delivered to view w/current focus
Tuesday, August 20, 13
EVENT LISTENER
• onClick()/View.OnClickListener()
• (boolean) onLongClick()/View.OnLongClickListener()
• onFocusChange()/View.OnFocusChangeListener()
• (boolean) onKey()/View.OnKeyListener()
• (boolean) onTouch()/View.OnTouchListener()
• onCreateContextMenu()/
View.OnCreateContextMenuListener()
• return true to stop event propagation
Tuesday, August 20, 13
VIEW SIZE
• FILL_PARENT = parent sized (minus pad)
• Now ā€œMATCH_PARENTā€ w/API Level 8
• WRAP_CONTENT = just big enough (plus pad)
Tuesday, August 20, 13
LAYING OUTVIEWS
• Gravity = position (i.e. left, right, center)
• Weight = extra/empty space allocation
• priority for expansion
• default weight is zero
Tuesday, August 20, 13
DIMENSIONVALUES
• Dimension values:
• dp/dip = density independent pixels
• sp = Scale independent pixels
• px = pixels
• in/mm = inches/millimeters
• pt = point (1/72 inch)
RecommendedNotRecommended
Tuesday, August 20, 13
DENSITY INDEPENDENT
PIXELS
• An abstract unit that is based on the physical density of the screen.These units
are relative to a 160 dpi (dots per inch) screen, so 160dp is always one inch
regardless of the screen density.
• The ratio of dp-to-pixel will change with the screen density, but not necessarily
in direct proportion.
• You should use these units when specifying view dimensions in your layout, so
the UI properly scales to render at the same actual size on different screens.
• The compiler accepts both "dip" and "dp", though "dp" is more consistent with
"sp".
Tuesday, August 20, 13
SCALE-INDEPENDENT PIXELS
• This is like the dp unit, but it is also scaled by the user's font
size preference.
• Recommend you use this unit when specifying font sizes, so
they will be adjusted for both the screen density and the
user's preference.
Recom
m
ended
for
Fonts
Tuesday, August 20, 13
COLORS
• #RGB
• #ARGB ( Alpha / Red / Green / Blue )
• #RRGGBB (i.e. #3d1ec4)
• #AARRGGBB
Tuesday, August 20, 13
VIEW /VIEWGROUP
Tuesday, August 20, 13
LAYOUTS (VIEWGROUPS)
• AbsoluteLayout -Absolute X,Y (depreciated)
• FrameLayout - Pinned to top left (simplest)
• LinearLayout - Horizontal orVertical - one per row
• RelativeLayout - Child specify relative widgets
• SlidingDrawer - Hides until dragged out by handle
• TableLayout - Rows & Columns
• ScrollView - Child can be larger than window
• TabWidget - Manages collection of ā€œTab Hostsā€
Tuesday, August 20, 13
ORIENTATION
• landscape or portrait
• dedicated layout file
• /res/layout = default layout directory
• /res/layout-land = landscape layout directory
• /res/layout-port = portrait layout directory
Tuesday, August 20, 13
DEMO - LAYOUTS &VIEWS
Tuesday, August 20, 13
TRACE LOGGING
• android.util.Log
• Log.d(ā€œtagā€,ā€œdebugā€);
• Log.e(ā€œtagā€,ā€œerrorā€);
• Log.i(ā€œtagā€,ā€œinformationalā€);
• Log.v(ā€œtagā€,ā€œverboseā€);
• Log.w(ā€œtagā€,ā€œwarningā€);
• View output using ā€œadb logcatā€
http://sn.im/android-log
Tuesday, August 20, 13
ADB - ANDROID DEBUG
BRIDGE
• Manages devices & emulators
• Issue debug commands
• Log output (adb logcat)
• Shell (adb shell)
• Copy files to/from emulator (adb push/pull)
http://sn.im/android_debug_bridge
Tuesday, August 20, 13
DEMO - ADB & LOGCAT
Tuesday, August 20, 13
BEST PRACTICES
Tuesday, August 20, 13
BEST PRACTICES
• Support multiple screen sizes and densities
• Use the Action Bar pattern - Good-bye menu button
• Build Dynamic UI with Fragments
• Know when to persist and restore state
• Don’t block main thread - use AsyncTask -Test with
StrictMode
http://sn.im/android-practices
http://sn.im/android-performance
Tuesday, August 20, 13
SUPPORT MULTIPLE SCREENS
SIZES & DENSITIES
• Use wrap_content, fill_parent, or dp units when
specifying dimensions in an XML layout file
• Do not use hard coded pixel values in your
application code
• Do not use AbsoluteLayout (it's deprecated)
• Supply alternative bitmap drawables for
different screen densities
• ldpi, mdpi, hdpi, xhdpi
http://sn.im/android-screens
Tuesday, August 20, 13
SCREEN SIZES & DENSITIES
Tuesday, August 20, 13
ACTION BAR
1. App Icon - optional ā€œupā€ affordance
2. View control - Navigation
3. Dynamic number of ā€œimportantā€ action buttons
4. Action overflow
http://sn.im/android-actionbar
http://actionbarsherlock.com/
Tuesday, August 20, 13
ASYNCTASK
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
Ā  Ā  Ā protected Long doInBackground(URL... urls) {
Ā  Ā  Ā  Ā  Ā int count = urls.length;
Ā  Ā  Ā  Ā  Ā long totalSize = 0;
Ā  Ā  Ā  Ā  Ā for (int i = 0; i < count; i++) {
Ā  Ā  Ā  Ā  Ā  Ā  Ā totalSize += Downloader.downloadFile(urls[i]);
Ā  Ā  Ā  Ā  Ā  Ā  Ā publishProgress((int) ((i / (float) count) * 100));
Ā  Ā  Ā  Ā  Ā  Ā  Ā // Escape early if cancel() is called
Ā  Ā  Ā  Ā  Ā  Ā  Ā if (isCancelled()) break;
Ā  Ā  Ā  Ā  Ā }
Ā  Ā  Ā  Ā  Ā return totalSize;
Ā  Ā  Ā }
Ā  Ā  Ā protected void onProgressUpdate(Integer... progress) {
Ā  Ā  Ā  Ā  Ā setProgressPercent(progress[0]);
Ā  Ā  Ā }
Ā  Ā  Ā protected void onPostExecute(Long result) {
Ā  Ā  Ā  Ā  Ā showDialog("Downloaded " + result + " bytes");
Ā  Ā  Ā }
Ā }
http://sn.im/android-asynctask
Tuesday, August 20, 13
STRICT MODE
• Place a policy on a thread - provides feedback when blocked
Ā public void onCreate() {
Ā  Ā  Ā if (DEVELOPER_MODE) {
Ā  Ā  Ā  Ā  Ā StrictMode.enableDefaults(); // Or configure
Ā  Ā  Ā }
Ā  Ā  Ā super.onCreate();
}
• http://sn.im/android-strictmode
• http://sn.im/android-strictmode-blog
Tuesday, August 20, 13
FIN.
Tuesday, August 20, 13
GOOD PLACESTO KNOW
• developer.android.com - Official developer site
• developers.google.com/android/ - Google on Android
• developers.google.com/events/io/ - Google I/O Replays
• stackoverflow.com - Great Q&A community
• android.stackexchange.com - End user Q&A
• vogella.com/android.html - Detailed tutorials
61
Tuesday, August 20, 13
ABOUT ME
• Live here in Boise - jim@mckeeth.org
• Lead Developer Evangelist for EmbarcaderoTechnologies
• www.embarcadero.com - Delphi for Android coming soon
• Google Developer Group - www.gdgb.org
• Boise Software Developers Group - www.bsdg.org
• Boise Code Camp - www.BoiseCodeCamp.com
Tuesday, August 20, 13

More Related Content

PPTX
Android technology _seminar_ ppt
vikas bharat
Ā 
PPTX
Android application design
Uday Sharma
Ā 
PDF
HTML5 or Android for Mobile Development?
Reto Meier
Ā 
PDF
7 Reasons Why Entrepreneurs Fail - Titanium Guide
TitaniumMarketing
Ā 
PPT
Why Do ENTREPRENEURS Fail?
geetuprats
Ā 
KEY
Android Development: The Basics
Mike Desjardins
Ā 
PPT
Disha's Tea Shop Photo Essay
ISYGrade6
Ā 
PPT
PolĆ­meros
Aninha Felix Vieira Dias
Ā 
Android technology _seminar_ ppt
vikas bharat
Ā 
Android application design
Uday Sharma
Ā 
HTML5 or Android for Mobile Development?
Reto Meier
Ā 
7 Reasons Why Entrepreneurs Fail - Titanium Guide
TitaniumMarketing
Ā 
Why Do ENTREPRENEURS Fail?
geetuprats
Ā 
Android Development: The Basics
Mike Desjardins
Ā 
Disha's Tea Shop Photo Essay
ISYGrade6
Ā 
PolĆ­meros
Aninha Felix Vieira Dias
Ā 

Viewers also liked (19)

PDF
Gamification
AivArs Platonovs
Ā 
PPTX
The daily retard
devdeepbag
Ā 
PDF
Weisskopf1983 cycle
economicgrowthcucea
Ā 
PPTX
ŠŸŃ€Š¾Š“Š²ŠøŠ¶ŠµŠ½ŠøŠµ на App Store. 10 шагов Šŗ ŃƒŃŠæŠµŃ…Ńƒ (Nevosoft)
Julia Lebedeva
Ā 
PPT
Nuestros alumnos en el taller mecƔnico
holepuncherpamplona
Ā 
PPT
De kleren van_sinterklaas
groep12pius10
Ā 
PPTX
Geometric Shapes
kewalson
Ā 
PPT
Web conferencing
mazyooonah
Ā 
ODP
Watchmen
Francesco Perani
Ā 
PDF
Stop Talking Start Doing: A kick in the pants in six parts
Richard Newton
Ā 
PDF
é€²åŒ–ć™ć‚‹ć‚Ŗćƒ¼ćƒ—ćƒ³ć‚½ćƒ¼ć‚¹ćƒ»ć‚Øćƒ³ć‚æćƒ¼ćƒ—ćƒ©ć‚¤ć‚ŗCMSがWebęˆ¦ē•„ć‚’å¤‰ćˆć‚‹
Hishikawa Takuro
Ā 
PPT
ELCM 390 orientation
lisalouisesw
Ā 
ODP
David pulido
holepuncherpamplona
Ā 
DOCX
4 introduccion a la ingenieria pag 37-40
Dirección de Educación Virtual
Ā 
PDF
å…‰é€Ÿćƒ†ćƒ¼ćƒžé–‹ē™ŗć®ć‚³ćƒ„
Hishikawa Takuro
Ā 
PDF
Incunabula edisi 1-april 2014
Tyo SBS
Ā 
PPTX
Martha
marthaenamiranda
Ā 
Gamification
AivArs Platonovs
Ā 
The daily retard
devdeepbag
Ā 
Weisskopf1983 cycle
economicgrowthcucea
Ā 
ŠŸŃ€Š¾Š“Š²ŠøŠ¶ŠµŠ½ŠøŠµ на App Store. 10 шагов Šŗ ŃƒŃŠæŠµŃ…Ńƒ (Nevosoft)
Julia Lebedeva
Ā 
Nuestros alumnos en el taller mecƔnico
holepuncherpamplona
Ā 
De kleren van_sinterklaas
groep12pius10
Ā 
Geometric Shapes
kewalson
Ā 
Web conferencing
mazyooonah
Ā 
Watchmen
Francesco Perani
Ā 
Stop Talking Start Doing: A kick in the pants in six parts
Richard Newton
Ā 
é€²åŒ–ć™ć‚‹ć‚Ŗćƒ¼ćƒ—ćƒ³ć‚½ćƒ¼ć‚¹ćƒ»ć‚Øćƒ³ć‚æćƒ¼ćƒ—ćƒ©ć‚¤ć‚ŗCMSがWebęˆ¦ē•„ć‚’å¤‰ćˆć‚‹
Hishikawa Takuro
Ā 
ELCM 390 orientation
lisalouisesw
Ā 
David pulido
holepuncherpamplona
Ā 
4 introduccion a la ingenieria pag 37-40
Dirección de Educación Virtual
Ā 
å…‰é€Ÿćƒ†ćƒ¼ćƒžé–‹ē™ŗć®ć‚³ćƒ„
Hishikawa Takuro
Ā 
Incunabula edisi 1-april 2014
Tyo SBS
Ā 
Ad

Similar to Introduction to Android Development with Java (20)

PDF
jQuery Mobile Deep Dive
Troy Miles
Ā 
PDF
Shiny r, live shared and explored
Alex Brown
Ā 
PDF
Making the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
Acquia
Ā 
PPTX
Introduction to jQuery
Alek Davis
Ā 
KEY
Opensocial
Julian Doherty
Ā 
PDF
Give Responsive Design a Mobile Performance Boost
Grgur Grisogono
Ā 
PDF
Backbone
Ynon Perek
Ā 
PPTX
Advanced #2 - ui perf
Vitali Pekelis
Ā 
PDF
Atlanta JUG - Integrating Spring Batch and Spring Integration
Gunnar Hillert
Ā 
PDF
Cross Platform Mobile Game Development
Allan Davis
Ā 
PDF
Getting Started With Material Design
Yasin Yildirim
Ā 
PDF
HackU 2013 : Introduction to Android programming
kalmeshhn
Ā 
PPT
First8 / AMIS Google Glass scanner development
Getting value from IoT, Integration and Data Analytics
Ā 
PDF
Testing iOS Apps
C4Media
Ā 
PPTX
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
Ā 
PDF
Bundling Client Side Assets
Timothy Oxley
Ā 
PDF
Android: Looking beyond the obvious
INVERS GmbH
Ā 
PPTX
Android material design lecture #2
Vitali Pekelis
Ā 
PDF
PhoneGap in 60 Minutes or Less
Troy Miles
Ā 
PDF
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Murat Yener
Ā 
jQuery Mobile Deep Dive
Troy Miles
Ā 
Shiny r, live shared and explored
Alex Brown
Ā 
Making the Switch, Part 1: Top 5 Things to Consider When Evaluating Drupal
Acquia
Ā 
Introduction to jQuery
Alek Davis
Ā 
Opensocial
Julian Doherty
Ā 
Give Responsive Design a Mobile Performance Boost
Grgur Grisogono
Ā 
Backbone
Ynon Perek
Ā 
Advanced #2 - ui perf
Vitali Pekelis
Ā 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Gunnar Hillert
Ā 
Cross Platform Mobile Game Development
Allan Davis
Ā 
Getting Started With Material Design
Yasin Yildirim
Ā 
HackU 2013 : Introduction to Android programming
kalmeshhn
Ā 
First8 / AMIS Google Glass scanner development
Getting value from IoT, Integration and Data Analytics
Ā 
Testing iOS Apps
C4Media
Ā 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
Ā 
Bundling Client Side Assets
Timothy Oxley
Ā 
Android: Looking beyond the obvious
INVERS GmbH
Ā 
Android material design lecture #2
Vitali Pekelis
Ā 
PhoneGap in 60 Minutes or Less
Troy Miles
Ā 
Eclipse Orion: The IDE in the Clouds (JavaOne 2013)
Murat Yener
Ā 
Ad

More from Jim McKeeth (17)

PDF
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
Jim McKeeth
Ā 
PDF
Announcing Codolex 2.0 from GDK Software
Jim McKeeth
Ā 
PDF
Smart Contracts - The Blockchain Beyond Bitcoin
Jim McKeeth
Ā 
PDF
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Jim McKeeth
Ā 
PDF
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
Jim McKeeth
Ā 
PDF
Day 5 of C++ Boot Camp - Stepping Up to Mobile
Jim McKeeth
Ā 
PDF
Android Services Skill Sprint
Jim McKeeth
Ā 
PDF
Creating Android Services with Delphi and RAD Studio 10 Seattle
Jim McKeeth
Ā 
PDF
Building a Thought Controlled Drone
Jim McKeeth
Ā 
PDF
Deep Dive into Futures and the Parallel Programming Library
Jim McKeeth
Ā 
PDF
Embarcadero's Connected Development
Jim McKeeth
Ā 
PDF
The Internet of Things and You - A Developers Guide to IoT
Jim McKeeth
Ā 
PDF
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Jim McKeeth
Ā 
PDF
Android voice skill sprint
Jim McKeeth
Ā 
PDF
Exploring the Brain Computer Interface
Jim McKeeth
Ā 
PDF
Hacking iBooks and ePub3 with JavaScript!
Jim McKeeth
Ā 
PDF
Inventing merit badge
Jim McKeeth
Ā 
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
Jim McKeeth
Ā 
Announcing Codolex 2.0 from GDK Software
Jim McKeeth
Ā 
Smart Contracts - The Blockchain Beyond Bitcoin
Jim McKeeth
Ā 
Rapid Prototyping Mobile IoT Projects with Arduino and Open Hardware
Jim McKeeth
Ā 
Day 3 of C++ Boot Camp - C++11 Language Deep Dive
Jim McKeeth
Ā 
Day 5 of C++ Boot Camp - Stepping Up to Mobile
Jim McKeeth
Ā 
Android Services Skill Sprint
Jim McKeeth
Ā 
Creating Android Services with Delphi and RAD Studio 10 Seattle
Jim McKeeth
Ā 
Building a Thought Controlled Drone
Jim McKeeth
Ā 
Deep Dive into Futures and the Parallel Programming Library
Jim McKeeth
Ā 
Embarcadero's Connected Development
Jim McKeeth
Ā 
The Internet of Things and You - A Developers Guide to IoT
Jim McKeeth
Ā 
Accessing REST & Backend as a Service (BaaS) - Developer Direct - Mobile Summ...
Jim McKeeth
Ā 
Android voice skill sprint
Jim McKeeth
Ā 
Exploring the Brain Computer Interface
Jim McKeeth
Ā 
Hacking iBooks and ePub3 with JavaScript!
Jim McKeeth
Ā 
Inventing merit badge
Jim McKeeth
Ā 

Recently uploaded (20)

PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
Ā 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
Ā 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
Ā 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
Ā 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
Ā 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
Ā 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
Ā 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
Ā 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
Ā 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
REPORT: Heating appliances market in Poland 2024
SPIUG
Ā 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
Ā 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
Ā 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
Ā 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
Ā 

Introduction to Android Development with Java

  • 2. AGENDA • Hello Android • Overview of Platform • PlatformTools • UI - XML • Views & Widgets • Architecture • Manifest & Permission • Activities & Intents • Debugging • Resources 2 Tuesday, August 20, 13
  • 3. ABOUT ME • Live here in Boise - [email protected] • Lead Developer Evangelist for EmbarcaderoTechnologies • www.embarcadero.com - Delphi for Android coming soon • Google Developer Group - www.gdgb.org • Boise Software Developers Group - www.bsdg.org • Boise Code Camp - www.BoiseCodeCamp.com Tuesday, August 20, 13
  • 5. GOOD PLACESTO KNOW • developer.android.com - Official developer site • developers.google.com/android/ - Google on Android • developers.google.com/events/io/ - Google I/O Replays • stackoverflow.com - Great Q&A community • android.stackexchange.com - End user Q&A • vogella.com/android.html - Detailed tutorials 5 Tuesday, August 20, 13
  • 7. ANDROID STACK • Tweaked Linux 2.6 • Tweaked Java (Dalvik) • Android OS • Android Apps • (Mostly open source) 7 Tuesday, August 20, 13
  • 8. VERSION HISTORY • November 5th, 2007 is Android’s Birthday • Each version has a version number, name and API level • Version number is most specific • Name is group of versions and API levels • Latest:Android 4.3 Jelly Bean (API 18) http://en.wikipedia.org/wiki/Android_version_history#Version_history_by_API_level Tuesday, August 20, 13
  • 9. VERSION POPULARITY As of August 2013 http://sn.im/platform-versions9 40% = Jelly Bean 63% >= ICS 96% >= Gingerbread 40% 23% 33% Tuesday, August 20, 13
  • 12. FRAMEWORK • DalvikVM • WebKit Browser • 2d Graphics Library, 3D w/OpenGL • SQLite • MPEG4, MP3, PNG, JPEG, etc • GSMTelephony, Bluetooth,WiFi • Camera, GPS, Compass,Accelerometer 12 Tuesday, August 20, 13
  • 13. CORE APPLICATIONS • Phone • eMail and SMS clients • Calendar • Contacts • Web Browser • Geographic Support via Google Maps 13 Tuesday, August 20, 13
  • 15. ANDROID SDK • http://developer.android.com/sdk • 3 Options • ADT Bundle (in Eclipse) • ā€œExisting IDEā€ download • Android Studio preview (in IntelliJ) 15 Tuesday, August 20, 13
  • 16. RELATEDTOOLS • Managers • Android SDK Manager • AVD Manager (AndroidVirtual Device) • Command-LineTools • adb (Android Debug Bridge -Your best friend!) • Others Tuesday, August 20, 13
  • 19. THE APK FILE • Zip file containing • Manifest, etc. • Compiled code • Resources & Assets Tuesday, August 20, 13
  • 21. Applica'on*Context* PARTS OF AN ANDROID APP Intent% Ac#vity( Class% Layout' String' Resources' Android' Manifest' Other& Classes& Drawables) Services( Broadcast) Receiver) Content& Providers& Ac#vity( Intent% Tuesday, August 20, 13
  • 22. PROJECT LAYOUT • AndroidManifest.xml • bin (APK file, compiled DEX files) • gen (generated resources) • res (resources you create) • src (Java source files) Tuesday, August 20, 13
  • 23. MANIFEST • Mandatory XML file ā€œAndroidManifest.xmlā€ • Describe application components • Default Activity • Permissions,Attributes • Non-SDK libraries http://sn.im/android-manifest Tuesday, August 20, 13
  • 24. MULTIPLE ACTIVITIES • Each Activity must be defined in manifest by class name and ā€œactionā€ • Activities reside on a ā€œtask stackā€ - visible activity is ā€œtop of stackā€ • Transition to an Activity using Intent • Return from Activity using Activity.finish() which pops off task stack Tuesday, August 20, 13
  • 25. ā€œRESā€ - RESOURCES • XML Files • drawable • layout • values • etc. • Graphics Tuesday, August 20, 13
  • 26. RES/LAYOUT • Each Activity should have dedicated layout XML file • Layout file specifies Activity appearance • Several layout types • Default LinearLayout provides sequential placement of widgets Tuesday, August 20, 13
  • 27. RES/VALUES • strings.xml contains String constants • Prefer strings.xml to hardcoded values (warnings) • L10N/I18N (Localization/Internationalization) Tuesday, August 20, 13
  • 28. • Application/Task is a stack of Activities • Visible activity = top of stack • Activities maintain state, even when notTOS • ā€œBackā€ button pops stack. • ā€œHomeā€ key would move stack to background • Selecting application brings to foreground or launches new instance APPLICATION AKATASK Tuesday, August 20, 13
  • 29. ANDROID.APP.ACTIVITY • Activity extends Context • Context contains application environment • ā€œa single focused thing a user can doā€ • An application consists of 1 or more Activities • Provides a default window to draw in, might be smaller than screen or float on top of others • UI elements are ā€œView(s)ā€ or widgets Tuesday, August 20, 13
  • 30. ANDROID.VIEW.VIEW • Extends java.lang.Object • Basic building block for UI components • Rectangular area on display • Responsible for drawing and event handling • View is the base class for widgets Tuesday, August 20, 13
  • 34. ANDROID.CONTENT.INTENT • Interprocess Communication messaging • Can launch an Activity or start a Service • new Intent(String action, Uri uri); • new Intent(Context packageCtx, Class class); • Intent.putExtra() • Intent.setAction() http://sn.im/android-intent Tuesday, August 20, 13
  • 35. INTENT (CONTINUED) • android.intent.action.MAIN (receiver on main activity) • many options:ACTION_VIEW, etc • category = extra information • MIME type • extras (i.e. getAction(), getExtra(), etc) Tuesday, August 20, 13
  • 36. INTENT USAGE • Activity Switch: • new Intent(this, NextActivity.class); • Web Browser: • Uri uri = Uri.parse(ā€œhttp://foobar.comā€); • new Intent(Intent.ACTION_VIEW, uri); • Phone Dialer: • Uri uri = Uri.parse(ā€œtel:4085551212ā€); • new Intent(Intent.ACTION_VIEW, uri); http://sn.im/android-intent Tuesday, August 20, 13
  • 38. VIEW LISTENERS • GUI is event driven • Event source: button press, mouse click, etc. • Listener catches event and performs action • Events are delivered to view w/current focus Tuesday, August 20, 13
  • 39. EVENT LISTENER • onClick()/View.OnClickListener() • (boolean) onLongClick()/View.OnLongClickListener() • onFocusChange()/View.OnFocusChangeListener() • (boolean) onKey()/View.OnKeyListener() • (boolean) onTouch()/View.OnTouchListener() • onCreateContextMenu()/ View.OnCreateContextMenuListener() • return true to stop event propagation Tuesday, August 20, 13
  • 40. VIEW SIZE • FILL_PARENT = parent sized (minus pad) • Now ā€œMATCH_PARENTā€ w/API Level 8 • WRAP_CONTENT = just big enough (plus pad) Tuesday, August 20, 13
  • 41. LAYING OUTVIEWS • Gravity = position (i.e. left, right, center) • Weight = extra/empty space allocation • priority for expansion • default weight is zero Tuesday, August 20, 13
  • 42. DIMENSIONVALUES • Dimension values: • dp/dip = density independent pixels • sp = Scale independent pixels • px = pixels • in/mm = inches/millimeters • pt = point (1/72 inch) RecommendedNotRecommended Tuesday, August 20, 13
  • 43. DENSITY INDEPENDENT PIXELS • An abstract unit that is based on the physical density of the screen.These units are relative to a 160 dpi (dots per inch) screen, so 160dp is always one inch regardless of the screen density. • The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. • You should use these units when specifying view dimensions in your layout, so the UI properly scales to render at the same actual size on different screens. • The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp". Tuesday, August 20, 13
  • 44. SCALE-INDEPENDENT PIXELS • This is like the dp unit, but it is also scaled by the user's font size preference. • Recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and the user's preference. Recom m ended for Fonts Tuesday, August 20, 13
  • 45. COLORS • #RGB • #ARGB ( Alpha / Red / Green / Blue ) • #RRGGBB (i.e. #3d1ec4) • #AARRGGBB Tuesday, August 20, 13
  • 47. LAYOUTS (VIEWGROUPS) • AbsoluteLayout -Absolute X,Y (depreciated) • FrameLayout - Pinned to top left (simplest) • LinearLayout - Horizontal orVertical - one per row • RelativeLayout - Child specify relative widgets • SlidingDrawer - Hides until dragged out by handle • TableLayout - Rows & Columns • ScrollView - Child can be larger than window • TabWidget - Manages collection of ā€œTab Hostsā€ Tuesday, August 20, 13
  • 48. ORIENTATION • landscape or portrait • dedicated layout file • /res/layout = default layout directory • /res/layout-land = landscape layout directory • /res/layout-port = portrait layout directory Tuesday, August 20, 13
  • 49. DEMO - LAYOUTS &VIEWS Tuesday, August 20, 13
  • 50. TRACE LOGGING • android.util.Log • Log.d(ā€œtagā€,ā€œdebugā€); • Log.e(ā€œtagā€,ā€œerrorā€); • Log.i(ā€œtagā€,ā€œinformationalā€); • Log.v(ā€œtagā€,ā€œverboseā€); • Log.w(ā€œtagā€,ā€œwarningā€); • View output using ā€œadb logcatā€ http://sn.im/android-log Tuesday, August 20, 13
  • 51. ADB - ANDROID DEBUG BRIDGE • Manages devices & emulators • Issue debug commands • Log output (adb logcat) • Shell (adb shell) • Copy files to/from emulator (adb push/pull) http://sn.im/android_debug_bridge Tuesday, August 20, 13
  • 52. DEMO - ADB & LOGCAT Tuesday, August 20, 13
  • 54. BEST PRACTICES • Support multiple screen sizes and densities • Use the Action Bar pattern - Good-bye menu button • Build Dynamic UI with Fragments • Know when to persist and restore state • Don’t block main thread - use AsyncTask -Test with StrictMode http://sn.im/android-practices http://sn.im/android-performance Tuesday, August 20, 13
  • 55. SUPPORT MULTIPLE SCREENS SIZES & DENSITIES • Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file • Do not use hard coded pixel values in your application code • Do not use AbsoluteLayout (it's deprecated) • Supply alternative bitmap drawables for different screen densities • ldpi, mdpi, hdpi, xhdpi http://sn.im/android-screens Tuesday, August 20, 13
  • 56. SCREEN SIZES & DENSITIES Tuesday, August 20, 13
  • 57. ACTION BAR 1. App Icon - optional ā€œupā€ affordance 2. View control - Navigation 3. Dynamic number of ā€œimportantā€ action buttons 4. Action overflow http://sn.im/android-actionbar http://actionbarsherlock.com/ Tuesday, August 20, 13
  • 58. ASYNCTASK private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { Ā  Ā  Ā protected Long doInBackground(URL... urls) { Ā  Ā  Ā  Ā  Ā int count = urls.length; Ā  Ā  Ā  Ā  Ā long totalSize = 0; Ā  Ā  Ā  Ā  Ā for (int i = 0; i < count; i++) { Ā  Ā  Ā  Ā  Ā  Ā  Ā totalSize += Downloader.downloadFile(urls[i]); Ā  Ā  Ā  Ā  Ā  Ā  Ā publishProgress((int) ((i / (float) count) * 100)); Ā  Ā  Ā  Ā  Ā  Ā  Ā // Escape early if cancel() is called Ā  Ā  Ā  Ā  Ā  Ā  Ā if (isCancelled()) break; Ā  Ā  Ā  Ā  Ā } Ā  Ā  Ā  Ā  Ā return totalSize; Ā  Ā  Ā } Ā  Ā  Ā protected void onProgressUpdate(Integer... progress) { Ā  Ā  Ā  Ā  Ā setProgressPercent(progress[0]); Ā  Ā  Ā } Ā  Ā  Ā protected void onPostExecute(Long result) { Ā  Ā  Ā  Ā  Ā showDialog("Downloaded " + result + " bytes"); Ā  Ā  Ā } Ā } http://sn.im/android-asynctask Tuesday, August 20, 13
  • 59. STRICT MODE • Place a policy on a thread - provides feedback when blocked Ā public void onCreate() { Ā  Ā  Ā if (DEVELOPER_MODE) { Ā  Ā  Ā  Ā  Ā StrictMode.enableDefaults(); // Or configure Ā  Ā  Ā } Ā  Ā  Ā super.onCreate(); } • http://sn.im/android-strictmode • http://sn.im/android-strictmode-blog Tuesday, August 20, 13
  • 61. GOOD PLACESTO KNOW • developer.android.com - Official developer site • developers.google.com/android/ - Google on Android • developers.google.com/events/io/ - Google I/O Replays • stackoverflow.com - Great Q&A community • android.stackexchange.com - End user Q&A • vogella.com/android.html - Detailed tutorials 61 Tuesday, August 20, 13
  • 62. ABOUT ME • Live here in Boise - [email protected] • Lead Developer Evangelist for EmbarcaderoTechnologies • www.embarcadero.com - Delphi for Android coming soon • Google Developer Group - www.gdgb.org • Boise Software Developers Group - www.bsdg.org • Boise Code Camp - www.BoiseCodeCamp.com Tuesday, August 20, 13