Professional Documents
Culture Documents
9 - Web - Services Based Apps Development
9 - Web - Services Based Apps Development
9 - Web - Services Based Apps Development
APPLICATION
DEVELOPMENT
9 - WEB SERVICES BASED APPS DEVELOPMENT
OVERVIEW
Dialog
AsyncTask
A dialog does not fill the screen and is normally used for modal events that require users to take an
action before they can proceed.
DIALOG
The Dialog class is the base class for dialogs, but you should avoid instantiating Dialog
directly. Instead, use one of the following subclasses:
Alert Dialog
A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.
DatePickerDialog or TimePickerDialog
A dialog with a pre-defined UI that allows the user to select a date or time.
ASYNC TASK
Android AsyncTask is an abstract class provided by Android which gives us the ability to perform heavy
tasks in the background and keep the UI thread light in order to make the application more responsive.
Android application runs on a single thread when launched. Due to this single thread model tasks that
take longer time to fetch the response can make the application non-responsive.
To avoid this we use android AsyncTask to perform the heavy tasks in background on a dedicated
thread and passing the results back to the UI thread.
Hence use of AsyncTask in android application keeps the UI thread responsive at all times.
ASYNC TASK
Methods of AsyncTask
onPreExecute()
Before doing background operation we can show something on screen like progressbar / Toast or any animation to
user.
We can use this onPreExecute Method in order to perform such task since this method will be called first in the
AsyncTask.
doInBackground(Params)
In this method we have to do background operation on background thread.
Operations in this method should not touch on any mainthread activities or fragments. We can pass parameters as
variable arguments (var-args)
onProgressUpdate(Progress)
While doing background operation if we want to update some information on UI, we can use this method.
onPostExecute(Result)
In this method we can update UI of background operation with the result.
ASYNC TASK
Generic Types of AsyncTask
TypeOfVarArgParams
ProgressValue
It contains information about progress units. While doing background operation we can update
information on UI using onProgressUpdate().
ResultValue
We can create GetPublciIP class as an inner class of our activity class as follows.
We can create GetIPDetails class as an inner class of our activity class as follows.
DEVELOPING A WEB SERVICE CONSUMER APP
We can override the onPreExecute Method of the GetIPDetails class as follows.