SlideShare a Scribd company logo
1 of 62
Introduction to Android
Development
Owain Lewis
owainrlewis@googlemail.com
@Ow_Zone
Goals of this session
• Give an overview of the Android Ecosystem
• Explain the core components of an Android
App
• Drink beer
• Create a simple working Android Application
• Drink more beer
Order of Service
Part 1:
Introduction to Android Development (45mins)
Beer Break
Part 2:
Live Coding – (45mins - or until it compiles)

Socialise
Android VM != JVM
Android Apps are:
• Written in java (mostly) • Compiled to bytecode
• Converted to .dex files • Run on the Dalvik VM
What’s inside an App
• Compiled Java source code
• Library dependencies e.g. MIME type lib
• XML Files – UI layouts, fragments etc.
• Images, sounds, videos etc.
• AndroidManifest.xml
Application Security

• Each App is assigned a user in Android linux
• Each linux process has it’s own VM
• Each Application runs in 1 process.
• Applications can request permissions to
system resources etc. - but user must agree.
App Fundamentals: UI
App Fundamentals: UI
UI Design... Wrong talk
Application Resources
• Additional files and static content that your
code uses
• Layouts for different types of devices and
device orientations.
• Images for different screen sizes and densities
• Referenced by unique ID within code
• Allow easy localization
Application Components
ApplicationManifest.xml
• Defines application components
• Identifies required permissions
• Defines required API level
• Definers hardware/software features required
• API libs to link against (e.g. maps API)

• Components not in the manifest aren’t usable
Application Components
Intro to Activities
• Single screen with UI
• Multiple activities exist in same app
• Activities work together but each is stand
alone
• Any app can trigger any activity in any app (if
allowed)
• More on that later…
Intro to Services
• Services generally run in the background
• Perform work that a user isn’t aware of
• Multiple components can make use of a
running service
• Example: GPS service, mp3 playing
Intro to Content Providers
• Mechanism to allow apps to interact with data
• Create, Query, Store, Update
• Can store data in multiple ways File System, DB,
network storage, or anywhere else the App can
get to.
• Apps can query any Content Provider if they have
permission
Intro to Broadcast Receivers
• A listener for system wide events
• No UI component
• Tend to be lightweight and do little work
• Example: Low battery handler
Intro to Intents
• Intent binds components to each other at
runtime (e.g. Event mechanism)
• Explicit Intent = message to activate specific
component by name
• Implicit Intent = message to activate type of
component
• Components define which Intent Types they
pick up with Intent Filters
Component Interoperability
• Any app can start any other apps component e.g.
use the camera app activity to capture pictures
– Don't need that code in your app
– Components run in the process of the holder app (e.g.
camera take pic activity runs under camera process).
– Android apps don't have single entry point (main
method)

• Activating a component in another app is not
allowed by system permissions - so use Intent.
Activating Components
• Activity: pass Intent to startActivity(…)
startActivityForResult() - gets a result
• Service: pass Intent to startService() or
bindService() if running already
• Broadcast: pass Intent to sendBroadcast(),
sendOrderedBroadcast() sendStickyBroadcast()

• Content: call query() on a ContentResolver
Make sense so far?
Activities
• One main per app – identified by Intent type
• Each new Activity pushes previous to back
stack
• Back button destroys current and pops
previous
• Callback methods are how the system
interacts with Activities – can be triggered by
Intents.
Activities – States
• Resumed/Running: up front and has focus
• Paused: Another Activity is on top of this one but this is still visible.
• Stopped: Backgrounded - still alive, not
attached to window manager
• The OS can kill activities without focus – but
will restart if possible.
Activities - Lifecycle
Activities
• Must be declared in Manifest
• Can declare IntentFilters – how other apps can
use the activity
• E.g. Action=MAIN and Category=LAUNCHER
tells Android this can be launched.
Activities - Manifest
Activities – Starting
• Explicit Intent to start Activity:
Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);

• Implicit Intent to start Activity:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, recipientArray);
startActivity(intent);

• Need a result?
– Call startActivityForResult() then implement onActivityResult() callback
– Get the result in an Intent
Activities - Stopping
• Call finish()
• To shutdown an activity you start call
finishActivity(…) – but Android will do this for you.
• Saving State: onSaveInstanceState()
• Rotating the screen destroys current Activity so good way to test restore logic.
Activities - Advanced
• Fragments
– Sub Activity with own lifecycle
– Can be an invisible worker

• Loaders (3.0 +)
– Async pull data into Activity Views
Services
• Long running operations - no UI.
– e.g. play music

• Service can run forever, but should know how to
stop itself
• Started service = runs in background - does it's
own thing until it stops
• Bound service = allows interaction/feedback.
Destroyed when all components unbind.
• Determine type of Activity by implementing
callbacks
Services - Callbacks
• onCreate()
• onStartCommand()
• onBind()
– which returns IBinder = the defined interface for
comms.

• onDestroy()
Services – Start/Stop
• startService(Intent)
• stopSelf()
• bindService (Intent service, ServiceConnection
conn, int flags)
• System destroys bound service – when clients
disconnect.
• Note that system can kill service without warning - but
will restart it
Services - Manifest
• Must declare all services in your
application's manifest file.
• Supports IntentFilters and permissions.
Services - Threads
• Services use the Main UI thread – this is bad.
• Your service should create threads it needs to
handle work
– If you want to handle multiple thread
simultaneously you need to manage this here.
– You need to manage stopping the thread too

• Alternative is to extend IntentService – offers
worker per request – one at a time.
Services - IntentService
• Creates a default worker thread that executes all intents
delivered to onStartCommand() separate from your
application's main thread.
•
Creates a work queue that passes one intent at a time to
your onHandleIntent() implementation, so you never have
to worry about multi-threading.
•
Stops the service after all start requests have been
handled, so you never have to call stopSelf().
•
Provides default implementation of onBind() that returns
null.
•
Provides a default implementation of onStartCommand()
that sends the intent to the work queue and then to your
onHandleIntent() implementation.
Services – User Comms
• Services can communicate with the user in a limited
way.
• Once running, a service can notify the user of events
using Toast Notifications or Status Bar Notifications.
• Toast notification is a message that appears on the
surface of the current window for a moment then
disappears.
• Status bar notification provides an icon in the status
bar with a message, which the user can select in order
to take an action (such as start an activity).
Services- Advanced
• Messengers
• AIDL
Broadcast Receivers
• Component that responds to system-wide
broadcast announcements
• Many broadcasts originate from the system
• Register for intents via Manifest
• Meant to do very little work
Broadcast Receivers
• Receiving a broadcast involves:
– Registering receiver in Manifest or dynamically
– Implementing:
• onReceive(Context, Intent)
Broadcast Receivers
• Normal broadcasts: Context.sendBroadcast()
– Asynchronous.
– All receivers of the broadcast are run in an undefined
order, often at the same time.

• Ordered broadcasts:
Context.sendOrderedBroadcast()

– Delivered to one receiver at a time.
– Each receiver executes in turn, and can propagate a
result to the next receiver, or abort the broadcast so
that it won't be passed to other receivers. Similar to
Filters in JEE
Content Providers
• Manage secure access to data - across process
boundaries
– Don't need one if you're just providing data to
own app
– Use ContentResolver to access data in a
ContentPtorvider

• -Android includes ContentProviders for
contacts, audio, video, images etc
Content Providers
• Data can be file (video etc) or Structured (tabular)
• Data is provided as tables (similar to relational dbs)
with primary keys (if needed)
• Content is referenced using a URI scheme
– e.g. content://user_dictionary/words
– Need to ask for permission to use a provider - this is done
in the manifest

• Define a query to perform against the URI.
– Returns a Cursor
– Cursor can be wrapped in a CursorAdaptor and bound to a
UI element.
Content Providers - Query
Content Providers
• Also can insert, update and delete.
• Batch access = process lots of data at a time
• Contract Classes = Constants used in accessing
a ContentProvider.
Content Providers
Intent and IntentFilter
• Activities, Services and Broadcast receivers are activated through
Intents
• Intent is a passive bundle of information. OS figures out how to get
it to the correct place.
• Intent is:
–
–
–
–
–
–

Optional component name
Action (e.g. ACTION_BATTERY_LOW) - you can invent your own
Data - URI of data and MIME type
Category - type of Intent (e.g. CATEGORY_LAUNCHER)
Extras - key/value pairs
Flags - how to deal with the intent

• Explicit Intent = named
• Implicit Intent = category of intents
Intent and IntentFilter
• IntentFilter tells the system which type of
Intent a component can handle
• Component can specify multiple filters
• Filter has fields that parallel the action, data,
and category fields of an Intent object
• Intent must match all 3 fields to be delivered
– Note that Intent may not specify a field…
IntentFilter Matching
• Action: Intent action must match at least one Filter
action. Intent can leave action blank and match
• Category: Every category in the Intent object must
match a category in the filter. Filter can list additional
categories, but it cannot omit any that are in the
intent.
– android.intent.category.DEFAULT must be implimented

• Data:
– No data = match
– More complex rules for data matching if specified
IntentFilter Matching
• Multiple filter match: Ask the user
Intent and IntentFilter
Processes and Threads
• One process per app. One Main thread is created
for the App process – this talks to the UI aka
UIThread
• General Rules:
– Do not block the UI thread
– Do not access the Android UI toolkit from outside the
UI thread

• Workarounds: Create own threads and use
Activity.runOnUiThread(Runnable)
View.post(Runnable)
View.postDelayed(Runnable, long)
Processes and Threads
AsyncTask
• AsyncTask allows you to perform asynchronous
work on your user interface. It performs the
blocking operations in a worker thread and then
publishes the results on the UI thread, without
requiring you to handle threads and/or handlers
yourself.
• Subclass AsyncTask and implement:
– doInBackground()
– onPreExecute, onPostExecute(), onProgressUpdate()

• Run Task from UIThread by calling execute()
AsyncTask
Development Tools
• Android Platform + SDK

• Android Developer Tools (ADT) for Eclipse
• Android Studio - Based on IntelliJ IDEA
• Currently in Early Access release
• Uses Gradle

• Emulators and Hardware debugging
Questions?
Beer!
Live Coding
Introduction to Android
Development
Owain Lewis
owainrlewis@googlemail.com
@Ow_Zone

More Related Content

Viewers also liked

Viewers also liked (14)

sebz slide presentation
sebz slide presentationsebz slide presentation
sebz slide presentation
 
Cap3b Historia del cine
Cap3b Historia del cineCap3b Historia del cine
Cap3b Historia del cine
 
O que aconteceu com os mundos virtuais no ensino?
O que aconteceu com os mundos virtuais no ensino?O que aconteceu com os mundos virtuais no ensino?
O que aconteceu com os mundos virtuais no ensino?
 
ExtJSで作るAIRアプリケーション
ExtJSで作るAIRアプリケーションExtJSで作るAIRアプリケーション
ExtJSで作るAIRアプリケーション
 
forestfire_course
forestfire_courseforestfire_course
forestfire_course
 
Language Educators: Shaping the Future in a New Era!
Language Educators:  Shaping the Future in a New Era!Language Educators:  Shaping the Future in a New Era!
Language Educators: Shaping the Future in a New Era!
 
Pre Assessment
Pre AssessmentPre Assessment
Pre Assessment
 
Martin karlssons vykortssamling st olof
Martin karlssons vykortssamling   st olofMartin karlssons vykortssamling   st olof
Martin karlssons vykortssamling st olof
 
Life
LifeLife
Life
 
Urvalsproblemetihistoria
UrvalsproblemetihistoriaUrvalsproblemetihistoria
Urvalsproblemetihistoria
 
IKT
IKTIKT
IKT
 
Recent PCI Hacks
Recent PCI HacksRecent PCI Hacks
Recent PCI Hacks
 
AINL 2016: Grigorieva
AINL 2016: GrigorievaAINL 2016: Grigorieva
AINL 2016: Grigorieva
 
141022 ic3 k semanticsofinnovation missikoff
141022 ic3 k semanticsofinnovation missikoff141022 ic3 k semanticsofinnovation missikoff
141022 ic3 k semanticsofinnovation missikoff
 

Similar to Introduction to Android Development

Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Andriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxAndriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxfaiz324545
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development TutorialGermán Bringas
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Project a day 2 android application fundamentals
Project a day 2   android application fundamentalsProject a day 2   android application fundamentals
Project a day 2 android application fundamentalsGoran Djonovic
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application DevelopmentAzfar Siddiqui
 
Android application development fundamentals
Android application development fundamentalsAndroid application development fundamentals
Android application development fundamentalsindiangarg
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & DatabasesMuhammad Sajid
 
Android architecture
Android architectureAndroid architecture
Android architectureDeepa Rahul
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basicsHasam Panezai
 
Creating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleCreating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleJim McKeeth
 
Android fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersAndroid fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersBoom Shukla
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxNgLQun
 

Similar to Introduction to Android Development (20)

Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Synapseindia android apps overview
Synapseindia android apps overviewSynapseindia android apps overview
Synapseindia android apps overview
 
Andriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptxAndriod Lecture 8 A.pptx
Andriod Lecture 8 A.pptx
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Android Development Tutorial
Android Development TutorialAndroid Development Tutorial
Android Development Tutorial
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
Android overview
Android overviewAndroid overview
Android overview
 
Project a day 2 android application fundamentals
Project a day 2   android application fundamentalsProject a day 2   android application fundamentals
Project a day 2 android application fundamentals
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android - Activity, Services
Android - Activity, ServicesAndroid - Activity, Services
Android - Activity, Services
 
Android Application Development
Android Application DevelopmentAndroid Application Development
Android Application Development
 
Android application development fundamentals
Android application development fundamentalsAndroid application development fundamentals
Android application development fundamentals
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basics
 
Creating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleCreating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 Seattle
 
Android fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginnersAndroid fundamentals and tutorial for beginners
Android fundamentals and tutorial for beginners
 
Android OS
Android OSAndroid OS
Android OS
 
Android101
Android101Android101
Android101
 
mobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptxmobile development with androiddfdgdfhdgfdhf.pptx
mobile development with androiddfdgdfhdgfdhf.pptx
 

Recently uploaded

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 

Introduction to Android Development

  • 1. Introduction to Android Development Owain Lewis owainrlewis@googlemail.com @Ow_Zone
  • 2. Goals of this session • Give an overview of the Android Ecosystem • Explain the core components of an Android App • Drink beer • Create a simple working Android Application • Drink more beer
  • 3. Order of Service Part 1: Introduction to Android Development (45mins) Beer Break Part 2: Live Coding – (45mins - or until it compiles) Socialise
  • 4. Android VM != JVM Android Apps are: • Written in java (mostly) • Compiled to bytecode • Converted to .dex files • Run on the Dalvik VM
  • 5.
  • 6. What’s inside an App • Compiled Java source code • Library dependencies e.g. MIME type lib • XML Files – UI layouts, fragments etc. • Images, sounds, videos etc. • AndroidManifest.xml
  • 7. Application Security • Each App is assigned a user in Android linux • Each linux process has it’s own VM • Each Application runs in 1 process. • Applications can request permissions to system resources etc. - but user must agree.
  • 11. Application Resources • Additional files and static content that your code uses • Layouts for different types of devices and device orientations. • Images for different screen sizes and densities • Referenced by unique ID within code • Allow easy localization
  • 13. ApplicationManifest.xml • Defines application components • Identifies required permissions • Defines required API level • Definers hardware/software features required • API libs to link against (e.g. maps API) • Components not in the manifest aren’t usable
  • 15. Intro to Activities • Single screen with UI • Multiple activities exist in same app • Activities work together but each is stand alone • Any app can trigger any activity in any app (if allowed) • More on that later…
  • 16. Intro to Services • Services generally run in the background • Perform work that a user isn’t aware of • Multiple components can make use of a running service • Example: GPS service, mp3 playing
  • 17. Intro to Content Providers • Mechanism to allow apps to interact with data • Create, Query, Store, Update • Can store data in multiple ways File System, DB, network storage, or anywhere else the App can get to. • Apps can query any Content Provider if they have permission
  • 18. Intro to Broadcast Receivers • A listener for system wide events • No UI component • Tend to be lightweight and do little work • Example: Low battery handler
  • 19. Intro to Intents • Intent binds components to each other at runtime (e.g. Event mechanism) • Explicit Intent = message to activate specific component by name • Implicit Intent = message to activate type of component • Components define which Intent Types they pick up with Intent Filters
  • 20. Component Interoperability • Any app can start any other apps component e.g. use the camera app activity to capture pictures – Don't need that code in your app – Components run in the process of the holder app (e.g. camera take pic activity runs under camera process). – Android apps don't have single entry point (main method) • Activating a component in another app is not allowed by system permissions - so use Intent.
  • 21. Activating Components • Activity: pass Intent to startActivity(…) startActivityForResult() - gets a result • Service: pass Intent to startService() or bindService() if running already • Broadcast: pass Intent to sendBroadcast(), sendOrderedBroadcast() sendStickyBroadcast() • Content: call query() on a ContentResolver
  • 23. Activities • One main per app – identified by Intent type • Each new Activity pushes previous to back stack • Back button destroys current and pops previous • Callback methods are how the system interacts with Activities – can be triggered by Intents.
  • 24. Activities – States • Resumed/Running: up front and has focus • Paused: Another Activity is on top of this one but this is still visible. • Stopped: Backgrounded - still alive, not attached to window manager • The OS can kill activities without focus – but will restart if possible.
  • 26. Activities • Must be declared in Manifest • Can declare IntentFilters – how other apps can use the activity • E.g. Action=MAIN and Category=LAUNCHER tells Android this can be launched.
  • 28. Activities – Starting • Explicit Intent to start Activity: Intent intent = new Intent(this, SignInActivity.class); startActivity(intent); • Implicit Intent to start Activity: Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_EMAIL, recipientArray); startActivity(intent); • Need a result? – Call startActivityForResult() then implement onActivityResult() callback – Get the result in an Intent
  • 29. Activities - Stopping • Call finish() • To shutdown an activity you start call finishActivity(…) – but Android will do this for you. • Saving State: onSaveInstanceState() • Rotating the screen destroys current Activity so good way to test restore logic.
  • 30. Activities - Advanced • Fragments – Sub Activity with own lifecycle – Can be an invisible worker • Loaders (3.0 +) – Async pull data into Activity Views
  • 31. Services • Long running operations - no UI. – e.g. play music • Service can run forever, but should know how to stop itself • Started service = runs in background - does it's own thing until it stops • Bound service = allows interaction/feedback. Destroyed when all components unbind. • Determine type of Activity by implementing callbacks
  • 32. Services - Callbacks • onCreate() • onStartCommand() • onBind() – which returns IBinder = the defined interface for comms. • onDestroy()
  • 33. Services – Start/Stop • startService(Intent) • stopSelf() • bindService (Intent service, ServiceConnection conn, int flags) • System destroys bound service – when clients disconnect. • Note that system can kill service without warning - but will restart it
  • 34.
  • 35. Services - Manifest • Must declare all services in your application's manifest file. • Supports IntentFilters and permissions.
  • 36. Services - Threads • Services use the Main UI thread – this is bad. • Your service should create threads it needs to handle work – If you want to handle multiple thread simultaneously you need to manage this here. – You need to manage stopping the thread too • Alternative is to extend IntentService – offers worker per request – one at a time.
  • 37. Services - IntentService • Creates a default worker thread that executes all intents delivered to onStartCommand() separate from your application's main thread. • Creates a work queue that passes one intent at a time to your onHandleIntent() implementation, so you never have to worry about multi-threading. • Stops the service after all start requests have been handled, so you never have to call stopSelf(). • Provides default implementation of onBind() that returns null. • Provides a default implementation of onStartCommand() that sends the intent to the work queue and then to your onHandleIntent() implementation.
  • 38.
  • 39. Services – User Comms • Services can communicate with the user in a limited way. • Once running, a service can notify the user of events using Toast Notifications or Status Bar Notifications. • Toast notification is a message that appears on the surface of the current window for a moment then disappears. • Status bar notification provides an icon in the status bar with a message, which the user can select in order to take an action (such as start an activity).
  • 41. Broadcast Receivers • Component that responds to system-wide broadcast announcements • Many broadcasts originate from the system • Register for intents via Manifest • Meant to do very little work
  • 42. Broadcast Receivers • Receiving a broadcast involves: – Registering receiver in Manifest or dynamically – Implementing: • onReceive(Context, Intent)
  • 43. Broadcast Receivers • Normal broadcasts: Context.sendBroadcast() – Asynchronous. – All receivers of the broadcast are run in an undefined order, often at the same time. • Ordered broadcasts: Context.sendOrderedBroadcast() – Delivered to one receiver at a time. – Each receiver executes in turn, and can propagate a result to the next receiver, or abort the broadcast so that it won't be passed to other receivers. Similar to Filters in JEE
  • 44. Content Providers • Manage secure access to data - across process boundaries – Don't need one if you're just providing data to own app – Use ContentResolver to access data in a ContentPtorvider • -Android includes ContentProviders for contacts, audio, video, images etc
  • 45. Content Providers • Data can be file (video etc) or Structured (tabular) • Data is provided as tables (similar to relational dbs) with primary keys (if needed) • Content is referenced using a URI scheme – e.g. content://user_dictionary/words – Need to ask for permission to use a provider - this is done in the manifest • Define a query to perform against the URI. – Returns a Cursor – Cursor can be wrapped in a CursorAdaptor and bound to a UI element.
  • 47. Content Providers • Also can insert, update and delete. • Batch access = process lots of data at a time • Contract Classes = Constants used in accessing a ContentProvider.
  • 49. Intent and IntentFilter • Activities, Services and Broadcast receivers are activated through Intents • Intent is a passive bundle of information. OS figures out how to get it to the correct place. • Intent is: – – – – – – Optional component name Action (e.g. ACTION_BATTERY_LOW) - you can invent your own Data - URI of data and MIME type Category - type of Intent (e.g. CATEGORY_LAUNCHER) Extras - key/value pairs Flags - how to deal with the intent • Explicit Intent = named • Implicit Intent = category of intents
  • 50. Intent and IntentFilter • IntentFilter tells the system which type of Intent a component can handle • Component can specify multiple filters • Filter has fields that parallel the action, data, and category fields of an Intent object • Intent must match all 3 fields to be delivered – Note that Intent may not specify a field…
  • 51. IntentFilter Matching • Action: Intent action must match at least one Filter action. Intent can leave action blank and match • Category: Every category in the Intent object must match a category in the filter. Filter can list additional categories, but it cannot omit any that are in the intent. – android.intent.category.DEFAULT must be implimented • Data: – No data = match – More complex rules for data matching if specified
  • 52. IntentFilter Matching • Multiple filter match: Ask the user
  • 54. Processes and Threads • One process per app. One Main thread is created for the App process – this talks to the UI aka UIThread • General Rules: – Do not block the UI thread – Do not access the Android UI toolkit from outside the UI thread • Workarounds: Create own threads and use Activity.runOnUiThread(Runnable) View.post(Runnable) View.postDelayed(Runnable, long)
  • 56. AsyncTask • AsyncTask allows you to perform asynchronous work on your user interface. It performs the blocking operations in a worker thread and then publishes the results on the UI thread, without requiring you to handle threads and/or handlers yourself. • Subclass AsyncTask and implement: – doInBackground() – onPreExecute, onPostExecute(), onProgressUpdate() • Run Task from UIThread by calling execute()
  • 58. Development Tools • Android Platform + SDK • Android Developer Tools (ADT) for Eclipse • Android Studio - Based on IntelliJ IDEA • Currently in Early Access release • Uses Gradle • Emulators and Hardware debugging
  • 60. Beer!
  • 62. Introduction to Android Development Owain Lewis owainrlewis@googlemail.com @Ow_Zone

Editor's Notes

  1. Intro:
  2. So these are my aims for todays session-from slide-beer from the disco-opportunity to ask questions – but feel fre to shout out whenever.
  3. Rough outline of the timings – but I’ve not actually practiced so we’ll see how we go.Someone shout if I’ve been talking on for hours.Live coding is a bit of an experiment.Feel free to hang arund after for a chat and with the wider group who organise JLUGS – Mat/Liam etc
  4. First a confession – this group is meant to be for JVM language users-But actually Android apps don’t run on the Java VM – they actually run on an open source VM called Dalvik.Dalvik is an alternative acrhitecture to the JVM.Good at runningn on machines with low memory and no/little swap space.Oracle are not big fans
  5. Outline of the android system architectureAndroid based on linux kernel 3 in latest, was 2.6 I thinkBunch of supported libraries provided by external providers – SSL etcAndroid runtime libs in C and Dalvik VMApp framework – provided as part of Android – full API docs available etcApplications sit on top of that stack – many provided by Google (not open source)And that’s what we can build too!
  6. This compiled APK runs against the Android runtime libraries which are on devices.When building an application we use the Android SDK (ADK) which includes those runtime libraries and a bunch of tools.
  7. Android is secure by design from the start – hard to build malware / bad apps.Applications execute within a sandboxFrom slide
  8. -Android UI is big - and really a whole talk on it's own--All Android UI components are in a hierarchy of View and ViewGroup objectsprovded by the SDK--Android provides a lot of these for you - but you can also create your own.----Can define UI in code - but much easier to do so in XML
  9. This is an example of a declaritive UI layout – making use of android provided UI elements.However this is not a talk about Android Uis….
  10. I’m not a UI guy- the tools help – but get a real designer That said – a UI is important – so I’ll leave learning the UI tools as an exercise for you guys.Along with the UI you’re going to need some resources
  11. Seperation of concerns in terms of designAllows app to provide multiple types of resources to suit various devices.
  12. Components are the building blocks of all Android applications – this is where the bulk of the java code lives.
  13. Manifest pulls it all together – this file is critical.This is where you can specify the requirements your app has from the device – Play picks these up.-Never assume these exist – can check in code if they really do.
  14. Focus of rest of talk.Components are the building blocks of all Android applications.-Nothing happens without the core components – no matter how good your UI layouts are Compoonent = a point through which the system (not necessarily auser) can interact with your app
  15. BR is the simplest component – but critical to a useful system
  16. Intents are the basis of a late binding event driven system – REALLY IMPORTANT IN ANDROIDFor Activities and Services: Intent defines: action to perform (e.g. view, send...) andcan specify URI to data (to perform on) - and other context the component may need.-Return values can also be sent as Intents.For BRec's: Intent = the announcement being broadcast e.g. "battery is low"-Content Provider:---Not activated by Intent---Activated when targeted by request from ContentResolver (abstraction layer - provides security)
  17. So that’s the brief overview – Now into the detail…
  18. 3 nested loops:onCreate - being created - Setup global state (define layout)onStart - about to become visible - register recieversetc that affect UIonResume - has become visible - fast codeonPause - losing focus - will get here a lot - only guaranteed closing state (if OS is in kill mode) so write crucial data hereonStop - lost focus, not visible - unregister receivers etconDestroy - about to go - clean up
  19. Saving state:-additional callback onSaveInstanceState()---Store key value pairs putXXX---Most widgets do this for you. Nice.-Get this back in onCreate() or onRestoreInstanceState()
  20. Data = URI
  21. Data = URI
  22. Data = URI
  23. Data = URI
  24. IDE based