SlideShare a Scribd company logo
Mobile Application Development
T. S. Indi, IT Department, WIT Solapur Page 1
Hadnout#4
Problem Statement: Design and implement Calculator (Arithmetic
Operations) App using AsyncTask concept.
Theory:
Use of AsyncTask:
Use of AsyncTask is to run tasks, which consists computationally
intensive operations, asynchronously from the UI threads.
Need of AsyncTask:
Implementing multithreading if multiple threads are involved in
updating the UI is more tedious. This can be done with simple mechanism
provided in Android is called AsyncTask.
AsyncTask (Asynchronous Task)
 It enables proper and easy use of the UI thread.
 It allow to perform background operations and publish results on
the UI thread without having to manipulate threads and/or
handlers.
 It is designed to be a helper class around Thread and Handler and
does not constitute a generic threading framework.
 It should ideally be used for short operations (a few seconds at the
most.)
 It is defined by a computation that runs on a background thread
and whose result is published on the UI thread.
 It is defined by 3 generic types, called Params, Progress and Result,
and 4 steps, called onPreExecute, doInBackground,
onProgressUpdate and onPostExecute.
Mobile Application Development
T. S. Indi, IT Department, WIT Solapur Page 2
AsyncTask deals with two key aspects:
(1) Execute the long-running task in the background (in a separate
thread)
Callback method: doInBackground(Params params..)
(2) Update the main thread as the task progresses or completes.
Callback method: onProgressUpdate(Progress… progress)
To meet above key aspects, AsyncTask class provides two key callback
methods:
(1) doInBackground(Params params…)
Gets executed on a separate thread in the background, different from
main thread.
is an ideal place for long-running tasks
(2) onProgressUpdate(Progress… progress)
Gets executed on the main thread
is suited to update the progress of the background task on UI.
(3) publishProgress(params)
Gets executed inside doInBackground(Params params…) method.
Helps to establish asynochronous communication between the
doInBackground () and onProgressUpdate()
An AsyncTask is implemented as a nested class of an Activity whose
UI it needs to Update.
[Reference: Book -“Mobile Apps Development” by Anubhav Pradhan, Anil V Deshpande]
Mobile Application Development
T. S. Indi, IT Department, WIT Solapur Page 3
Design:
Steps:
1) Design an app to perform Arithmetic Operations such as Addition,
Subtraction and Multiplication for integer numbers.
2) Design layout with two TextView, two EditText, three TextView to
display results and “Submit” button.
3) User enters two numbers and click on “Submit” button.
4) On click of “Submit” button, two numbers passed to Asynchronous
Task thread to perform Addition, Subtraction and Multiplication of
two numbers.
5) Results performed in AsyncTask will be updated on main layout.
Questions:
1) What is asynTask in Android?
2) Illustrate the benefits of AsyncTask over Threads for implementing
long-running tasks.
3) Difference between AsyncTask & Handler in Android.
4) Explain concept of Handler & Looper in Android.
5) Explain event-handling paradigm with the help of example.

More Related Content

PDF
MobileAppDev Handout#7
PDF
MobileAppDev Handout#10
PDF
MobileAppDev Handout#5
PDF
MobileAppDev Handout#6
PDF
MobileAppDev Handout#9
PDF
MobileAppDev Handout#8
PDF
MobileAppDev Handout#3
PDF
MobileAppDev Handout#1
MobileAppDev Handout#7
MobileAppDev Handout#10
MobileAppDev Handout#5
MobileAppDev Handout#6
MobileAppDev Handout#9
MobileAppDev Handout#8
MobileAppDev Handout#3
MobileAppDev Handout#1

What's hot (20)

PPTX
Android application project presentation.
PPTX
5 beginner android application development foundation
PDF
Mobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
PPTX
Android app ppt
PPT
job job
PPTX
Android task manager project presentation
PPTX
Iterative development & rational unified process
DOCX
Android article
PDF
Making Android Easier to Develop
PDF
Mobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
PDF
Application for Data Sync Between Different geo Locations
PDF
Introduction to Android Programming by Dr.M.Pyingkodi-kongu engineering c...
PDF
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
PDF
Difference between system software and application software
PDF
Real-time Text Audio to Video PPT Converter Tablet App
PPTX
Flutter single codebase to build your dream application for i os and android
PPT
Case study on tablet application for real time video, audio and ppt conversion
PPTX
Extensibility in application
PDF
SeMA: A Design Methodology for Building Secure Android Apps
PPTX
Flutter app development company
Android application project presentation.
5 beginner android application development foundation
Mobile Programming - 9 Profile UI, Navigation Basic and Splash Screen
Android app ppt
job job
Android task manager project presentation
Iterative development & rational unified process
Android article
Making Android Easier to Develop
Mobile Programming - 8 Progress Bar, Draggable Music Knob, Timer
Application for Data Sync Between Different geo Locations
Introduction to Android Programming by Dr.M.Pyingkodi-kongu engineering c...
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
Difference between system software and application software
Real-time Text Audio to Video PPT Converter Tablet App
Flutter single codebase to build your dream application for i os and android
Case study on tablet application for real time video, audio and ppt conversion
Extensibility in application
SeMA: A Design Methodology for Building Secure Android Apps
Flutter app development company
Ad

Similar to MobileAppDev Handout#4 (20)

PDF
[Android] Multiple Background Threads
PDF
Android development training programme , Day 3
PDF
Session 9 Android Web Services - Part 2.pdf
PDF
Internals of AsyncTask
PDF
PDF
Asynchronous Programming in Android
PPTX
Background Thread
PPT
Android - Thread, Handler and AsyncTask
PPTX
Introduction to Android - Session 3
ODP
Android training day 5
PPTX
Session #6 loaders and adapters
PPTX
Android session-5-sajib
PDF
Async Await for Mobile Apps
PPTX
Android async task
PPTX
Android async task
PDF
Android Threading
PDF
Android best practices
PDF
Think Async: Understanding the Complexity of Multithreading - Avi Kabizon & A...
ODP
Android App Development - 07 Threading
DOCX
androidSample
[Android] Multiple Background Threads
Android development training programme , Day 3
Session 9 Android Web Services - Part 2.pdf
Internals of AsyncTask
Asynchronous Programming in Android
Background Thread
Android - Thread, Handler and AsyncTask
Introduction to Android - Session 3
Android training day 5
Session #6 loaders and adapters
Android session-5-sajib
Async Await for Mobile Apps
Android async task
Android async task
Android Threading
Android best practices
Think Async: Understanding the Complexity of Multithreading - Avi Kabizon & A...
Android App Development - 07 Threading
androidSample
Ad

More from trupti1976 (11)

PDF
MobileAppDev Handout#2
PDF
CP Handout#10
PDF
CP Handout#9
PDF
CP Handout#8
PDF
CP Handout#7
PDF
CP Handout#6
PDF
CP Handout#5
PDF
CP Handout#4
PDF
CP Handout#3
PDF
CP Handout#2
PDF
CP Handout#1
MobileAppDev Handout#2
CP Handout#10
CP Handout#9
CP Handout#8
CP Handout#7
CP Handout#6
CP Handout#5
CP Handout#4
CP Handout#3
CP Handout#2
CP Handout#1

Recently uploaded (20)

PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
additive manufacturing of ss316l using mig welding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Current and future trends in Computer Vision.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Well-logging-methods_new................
PDF
composite construction of structures.pdf
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Internet of Things (IOT) - A guide to understanding
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Safety Seminar civil to be ensured for safe working.
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
additive manufacturing of ss316l using mig welding
Model Code of Practice - Construction Work - 21102022 .pdf
CYBER-CRIMES AND SECURITY A guide to understanding
OOP with Java - Java Introduction (Basics)
Current and future trends in Computer Vision.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Foundation to blockchain - A guide to Blockchain Tech
Well-logging-methods_new................
composite construction of structures.pdf
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT

MobileAppDev Handout#4

  • 1. Mobile Application Development T. S. Indi, IT Department, WIT Solapur Page 1 Hadnout#4 Problem Statement: Design and implement Calculator (Arithmetic Operations) App using AsyncTask concept. Theory: Use of AsyncTask: Use of AsyncTask is to run tasks, which consists computationally intensive operations, asynchronously from the UI threads. Need of AsyncTask: Implementing multithreading if multiple threads are involved in updating the UI is more tedious. This can be done with simple mechanism provided in Android is called AsyncTask. AsyncTask (Asynchronous Task)  It enables proper and easy use of the UI thread.  It allow to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.  It is designed to be a helper class around Thread and Handler and does not constitute a generic threading framework.  It should ideally be used for short operations (a few seconds at the most.)  It is defined by a computation that runs on a background thread and whose result is published on the UI thread.  It is defined by 3 generic types, called Params, Progress and Result, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.
  • 2. Mobile Application Development T. S. Indi, IT Department, WIT Solapur Page 2 AsyncTask deals with two key aspects: (1) Execute the long-running task in the background (in a separate thread) Callback method: doInBackground(Params params..) (2) Update the main thread as the task progresses or completes. Callback method: onProgressUpdate(Progress… progress) To meet above key aspects, AsyncTask class provides two key callback methods: (1) doInBackground(Params params…) Gets executed on a separate thread in the background, different from main thread. is an ideal place for long-running tasks (2) onProgressUpdate(Progress… progress) Gets executed on the main thread is suited to update the progress of the background task on UI. (3) publishProgress(params) Gets executed inside doInBackground(Params params…) method. Helps to establish asynochronous communication between the doInBackground () and onProgressUpdate() An AsyncTask is implemented as a nested class of an Activity whose UI it needs to Update. [Reference: Book -“Mobile Apps Development” by Anubhav Pradhan, Anil V Deshpande]
  • 3. Mobile Application Development T. S. Indi, IT Department, WIT Solapur Page 3 Design: Steps: 1) Design an app to perform Arithmetic Operations such as Addition, Subtraction and Multiplication for integer numbers. 2) Design layout with two TextView, two EditText, three TextView to display results and “Submit” button. 3) User enters two numbers and click on “Submit” button. 4) On click of “Submit” button, two numbers passed to Asynchronous Task thread to perform Addition, Subtraction and Multiplication of two numbers. 5) Results performed in AsyncTask will be updated on main layout. Questions: 1) What is asynTask in Android? 2) Illustrate the benefits of AsyncTask over Threads for implementing long-running tasks. 3) Difference between AsyncTask & Handler in Android. 4) Explain concept of Handler & Looper in Android. 5) Explain event-handling paradigm with the help of example.