SlideShare a Scribd company logo
Android : Doing things in Background
Who am I ?
Aman Alam
Co-Founder,
Happily Coded Mobile Solutions,
Assistant Organizer, BlrDroid
Bangalore, IN
Happilycoded.com
@amanalam
What

Offloading UI Thread, doing heavy work in background thread

2
Why
- Network on Main Thread is not allowed
- Slow UI thread makes the ANR error show up
- Nobody likes slow apps
- A bit about UI Thread

3
Solutions
- Java Threads
- Handlers
- AsyncTask
- Service
- IntentService
- Getting Results back
4
What to use, and when
- Java Threads : Avoid
- Handlers : very small tasks
- AsyncTask : Simple tasks related to current activity
only
- Service : Somewhat heavy, independence needed
- IntentService : Easy handling of multiple requests
One shot to kill all doesn't work
5
Getting our hands dirty

Code Time!

- Getting results back
- Java Threads
- Handlers
- AsyncTask
- Service
- IntentService
6
Further Reading
- Bound Services :
http://developer.android.com/guide/components/bound-services.html

- Keeping the app responsive :
http://developer.android.com/training/articles/perf-anr.html

- Working with IntentServices :
http://developer.android.com/training/run-background-service/create-service.html

- Dealing with normal Thread :
http://stackoverflow.com/a/6463591/243709

7
Further Reading

- Background processing :
http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html

- Code:
https://github.com/Sheikh-Aman/Teach/tree/master/BackgroundDemo

8
That's All Folks!
Thank You!
Aman Alam

Contact:

Co-Founder,

aman@blrdroid.org

Happily Coded Mobile Solutions,

@amanalam

Bangalore, IN

gplus.to/SheikhAman

Happilycoded.com

www.sheikhaman.com

@amanalam

More Related Content

Similar to Android : Background Processing

Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
Utkarsh Mankad
 

Similar to Android : Background Processing (20)

Optimizing Android Development
Optimizing Android DevelopmentOptimizing Android Development
Optimizing Android Development
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful Threading
 
Android 101 Session @thejunction32
Android 101 Session @thejunction32Android 101 Session @thejunction32
Android 101 Session @thejunction32
 
Android Connecting to internet Part 2
Android  Connecting to internet Part 2Android  Connecting to internet Part 2
Android Connecting to internet Part 2
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Wireless Wednesdays: Part 1
Wireless Wednesdays: Part 1Wireless Wednesdays: Part 1
Wireless Wednesdays: Part 1
 
Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!Frontend Monoliths: Run if you can!
Frontend Monoliths: Run if you can!
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012
 
Performance optimization for Android
Performance optimization for AndroidPerformance optimization for Android
Performance optimization for Android
 
ITB2015 - Crash Course in Ionic + AngularJS
ITB2015 - Crash Course in Ionic + AngularJSITB2015 - Crash Course in Ionic + AngularJS
ITB2015 - Crash Course in Ionic + AngularJS
 
Real World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVCReal World AngularJS recipes: beyond TodoMVC
Real World AngularJS recipes: beyond TodoMVC
 
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
Real World AngularJS recipes: beyond TodoMVC - Carlo Bonamico, Sonia Pini - C...
 
Asynchronous Programming in Android
Asynchronous Programming in AndroidAsynchronous Programming in Android
Asynchronous Programming in Android
 
Internals of AsyncTask
Internals of AsyncTask Internals of AsyncTask
Internals of AsyncTask
 
Responsive Interfaces
Responsive InterfacesResponsive Interfaces
Responsive Interfaces
 
Threads handlers and async task, widgets - day8
Threads   handlers and async task, widgets - day8Threads   handlers and async task, widgets - day8
Threads handlers and async task, widgets - day8
 
Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6 Android Jam - Services & Notifications - Udacity Lesson 6
Android Jam - Services & Notifications - Udacity Lesson 6
 
Dori waldman android _course_2
Dori waldman android _course_2Dori waldman android _course_2
Dori waldman android _course_2
 
PWA
PWAPWA
PWA
 
Agile Software Development by Sencha
Agile Software Development by SenchaAgile Software Development by Sencha
Agile Software Development by Sencha
 

Recently uploaded

Recently uploaded (20)

To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Server-Driven User Interface (SDUI) at Priceline
Server-Driven User Interface (SDUI) at PricelineServer-Driven User Interface (SDUI) at Priceline
Server-Driven User Interface (SDUI) at Priceline
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Motion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in TechnologyMotion for AI: Creating Empathy in Technology
Motion for AI: Creating Empathy in Technology
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.Enterprise Security Monitoring, And Log Management.
Enterprise Security Monitoring, And Log Management.
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 

Android : Background Processing

  • 1. Android : Doing things in Background Who am I ? Aman Alam Co-Founder, Happily Coded Mobile Solutions, Assistant Organizer, BlrDroid Bangalore, IN Happilycoded.com @amanalam
  • 2. What Offloading UI Thread, doing heavy work in background thread 2
  • 3. Why - Network on Main Thread is not allowed - Slow UI thread makes the ANR error show up - Nobody likes slow apps - A bit about UI Thread 3
  • 4. Solutions - Java Threads - Handlers - AsyncTask - Service - IntentService - Getting Results back 4
  • 5. What to use, and when - Java Threads : Avoid - Handlers : very small tasks - AsyncTask : Simple tasks related to current activity only - Service : Somewhat heavy, independence needed - IntentService : Easy handling of multiple requests One shot to kill all doesn't work 5
  • 6. Getting our hands dirty Code Time! - Getting results back - Java Threads - Handlers - AsyncTask - Service - IntentService 6
  • 7. Further Reading - Bound Services : http://developer.android.com/guide/components/bound-services.html - Keeping the app responsive : http://developer.android.com/training/articles/perf-anr.html - Working with IntentServices : http://developer.android.com/training/run-background-service/create-service.html - Dealing with normal Thread : http://stackoverflow.com/a/6463591/243709 7
  • 8. Further Reading - Background processing : http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html - Code: https://github.com/Sheikh-Aman/Teach/tree/master/BackgroundDemo 8
  • 9. That's All Folks! Thank You! Aman Alam Contact: Co-Founder, aman@blrdroid.org Happily Coded Mobile Solutions, @amanalam Bangalore, IN gplus.to/SheikhAman Happilycoded.com www.sheikhaman.com @amanalam