SlideShare a Scribd company logo
Android asynchronous programming
Asynchronous Programming
•Sync & Async
•Thread & Handler
•AsyncTask
•RxAndroid/RxJava
2
Sync & Async
3
Sync & Async
4
Sync & Async
5
Synchronous call Asynchronous call
● Caller WAITS for method to
complete
● Blocking
● Easy to program/understand
● Method returns immediately to
caller and executes callback
● Non-blocking
● Run several methods
concurrently
● Scalability
● Harder to program
Thread & Handlerhttps://developer.android.com/training/multiple-threads/communicate-ui.html
6
Thread
7
Thread
8
What is it?
• A basic unit of CPU utilization
• Lightweight process
• Multiple threads are executed within a process
Handler
9
Handler
10
What is it?
• Part of the Android system's framework
• Communicate between threads:
– Send message
– Process message
Handler
11
Thread & Handlerhttps://developer.android.com/training/multiple-threads/communicate-ui.html
12
AsyncTaskhttps://developer.android.com/reference/android/os/AsyncTask.html
What is it?
• Helper class around Thread and Handler
• Perform background operations
• Publish results on the UI thread
13
AsyncTaskhttps://developer.android.com/reference/android/os/AsyncTask.html
14
AsyncTaskhttps://developer.android.com/reference/android/os/AsyncTask.html
15
When to use? Trigger Triggered From Runs On Limitations /
Drawbacks
- Relatively long
task (UI thread
blocking) with a
need to
communicate with
main thread.[3]
- For tasks in
parallel use
multiple instances
OR Executor [1]
Call to method
execute()
Main Thread Worker thread.
However, Main
thread methods
may be invoked in
between to
publish progress.
- one instance can
only be executed
once (hence
cannot run in a
loop) [2]
- Must be created
and executed from
the Main thread
RxAndroidhttp://reactivex.io/
16
RxAndroidhttp://reactivex.io/
17
ReactiveX is:
• A combination of the best ideas from
– The Observer pattern
– The Iterator pattern
– Functional programming
• An API for asynchronous programming with observable streams.
RxAndroidhttp://reactivex.io/
18
RxAndroidhttps://nhancv.github.io/product/rxjava/
19
Observable
In ReactiveX an observer subscribes to an Observable.
• onNext
• onError
• onCompleted
RxAndroidhttps://nhancv.github.io/product/rxjava/
20
Observer
• An observer subscribes to an Observable.
• An Observable emits items or sends notifications to its observers by
calling the observers’ methods.
RxAndroidhttps://nhancv.github.io/product/rxjava/
21
PublishSubject
• Emits to an observer only those items that are emitted by the source
Observable(s) subsequent to the time of the subscription.
RxAndroidhttps://nhancv.github.io/product/rxjava/
22
Scheduler
• The SubscribeOn operator designates which thread the Observable will
begin operating on.
• The ObserveOn operator specifies a different Scheduler that the
Observable will use to send notifications to its observers.
Varieties of Scheduler
• Schedulers.computation( )
• Schedulers.io( )
• Schedulers.newThread( )
RxAndroidhttps://nhancv.github.io/product/rxjava/
23
RxAndroidhttps://nhancv.github.io/product/rxjava/
24
Operators
Create observable Transforming
• create
• defer
• just
• from
• map
• flat map
RxAndroidhttp://reactivex.io/
25
Operators
Filtering Combining
• debounce
• distinct
• filter
• merge
• zip
26
THANK YOU
for
YOUR ATTENTION
https://github.com/nhancv/nc-android-async
27

More Related Content

What's hot (20)

PDF
Reactive programming with Rxjava
Christophe Marchal
 
PPTX
Open source tools for optimizing your peering infrastructure @ DE-CIX TechMee...
Daniel Czerwonk
 
PPT
ruby + websocket + haproxy
Mathieu Elie
 
PPT
Asynchronous Programming in C# - Part 1
Mindfire Solutions
 
PDF
Akka HTTP with Scala
Knoldus Inc.
 
PDF
SFO15-TR6: Server Ecosystem Day (Part 6A)
Linaro
 
KEY
Concurrency in ruby
Marco Borromeo
 
PDF
Php Inspections (EA Extended): The Cookbook
Vladimir Reznichenko
 
PDF
8th Athens Big Data Meetup - 1st Talk - Riding The Streaming Wave DIY Style
Athens Big Data
 
PPTX
Notes on Netty baics
Rick Hightower
 
PDF
Introduction to K6
Knoldus Inc.
 
PDF
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
tdc-globalcode
 
PDF
RxSwift
RomanPanichkin
 
PDF
BSides Rochester 2018: Esteban Rodriguez: Ducky In The Middle: Injecting keys...
JosephTesta9
 
PDF
February'16 SDG - Spring'16 new features
Josep Vall-llovera
 
PPTX
Netty Notes Part 2 - Transports and Buffers
Rick Hightower
 
PDF
September SDG - Lightning
Josep Vall-llovera
 
PDF
2021.laravelconf.tw.slides1
LiviaLiaoFontech
 
PDF
Jenkins & Hipchat integration
Mohit Tater
 
PDF
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
jazoon13
 
Reactive programming with Rxjava
Christophe Marchal
 
Open source tools for optimizing your peering infrastructure @ DE-CIX TechMee...
Daniel Czerwonk
 
ruby + websocket + haproxy
Mathieu Elie
 
Asynchronous Programming in C# - Part 1
Mindfire Solutions
 
Akka HTTP with Scala
Knoldus Inc.
 
SFO15-TR6: Server Ecosystem Day (Part 6A)
Linaro
 
Concurrency in ruby
Marco Borromeo
 
Php Inspections (EA Extended): The Cookbook
Vladimir Reznichenko
 
8th Athens Big Data Meetup - 1st Talk - Riding The Streaming Wave DIY Style
Athens Big Data
 
Notes on Netty baics
Rick Hightower
 
Introduction to K6
Knoldus Inc.
 
TDC2017 | São Paulo - Trilha Containers How we figured out we had a SRE team ...
tdc-globalcode
 
BSides Rochester 2018: Esteban Rodriguez: Ducky In The Middle: Injecting keys...
JosephTesta9
 
February'16 SDG - Spring'16 new features
Josep Vall-llovera
 
Netty Notes Part 2 - Transports and Buffers
Rick Hightower
 
September SDG - Lightning
Josep Vall-llovera
 
2021.laravelconf.tw.slides1
LiviaLiaoFontech
 
Jenkins & Hipchat integration
Mohit Tater
 
JAZOON'13 - Nikita Salnikov-Tarnovski - Multiplatform Java application develo...
jazoon13
 

Similar to Android asynchronous programming (20)

PDF
Reactive programming on Android
Tomáš Kypta
 
PDF
Streamlining with rx
Akhil Dad
 
PPTX
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar
 
PDF
Programming Sideways: Asynchronous Techniques for Android
Emanuele Di Saverio
 
PPTX
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
PROIDEA
 
PDF
Asynchronous Programming in Android
John Pendexter
 
PPTX
Taming Asynchrony using RxJS
Angelo Simone Scotto
 
PDF
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft
 
PPTX
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
PDF
RxJava@DAUG
Maxim Volgin
 
PPTX
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PPTX
Rxandroid
Thinh Thanh
 
PPTX
RxAndroid
Thinh Thanh
 
PPTX
Reactive programming with RxAndroid
Savvycom Savvycom
 
PDF
RxJava pour Android : présentation lors du GDG Android Montréal
Sidereo
 
PDF
RxJava in practice
Javier Gamarra
 
PPTX
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
PDF
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
PPTX
Rx java in action
Pratama Nur Wijaya
 
PDF
The Mayans Lost Guide to RxJava on Android
Fernando Cejas
 
Reactive programming on Android
Tomáš Kypta
 
Streamlining with rx
Akhil Dad
 
Reactive Programming on Android - RxAndroid - RxJava
Ali Muzaffar
 
Programming Sideways: Asynchronous Techniques for Android
Emanuele Di Saverio
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
PROIDEA
 
Asynchronous Programming in Android
John Pendexter
 
Taming Asynchrony using RxJS
Angelo Simone Scotto
 
Sperasoft Talks: RxJava Functional Reactive Programming on Android
Sperasoft
 
Reactive Programming in Java 8 with Rx-Java
Kasun Indrasiri
 
RxJava@DAUG
Maxim Volgin
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Rxandroid
Thinh Thanh
 
RxAndroid
Thinh Thanh
 
Reactive programming with RxAndroid
Savvycom Savvycom
 
RxJava pour Android : présentation lors du GDG Android Montréal
Sidereo
 
RxJava in practice
Javier Gamarra
 
Intro to Functional Programming with RxJava
Mike Nakhimovich
 
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
Rx java in action
Pratama Nur Wijaya
 
The Mayans Lost Guide to RxJava on Android
Fernando Cejas
 
Ad

More from Nhan Cao (6)

PPTX
Android component programming
Nhan Cao
 
PPTX
OOp, core language & principles
Nhan Cao
 
PPTX
Flutter talkshow
Nhan Cao
 
PPTX
Ar
Nhan Cao
 
PPTX
Android tdd
Nhan Cao
 
PPTX
React native starter
Nhan Cao
 
Android component programming
Nhan Cao
 
OOp, core language & principles
Nhan Cao
 
Flutter talkshow
Nhan Cao
 
Android tdd
Nhan Cao
 
React native starter
Nhan Cao
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
July Patch Tuesday
Ivanti
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 

Android asynchronous programming