Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
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.