9 - Web - Services Based Apps Development

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

INTE 34253 - MOBILE

APPLICATION
DEVELOPMENT
9 - WEB SERVICES BASED APPS DEVELOPMENT
OVERVIEW

 Dialog

 AsyncTask

 Developing a Web Service Consumer App


DIALOG
 A dialog is a small window that prompts the user to make a decision or enter additional information.

 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

 AsyncTask has three generic types (AsyncTask<Params, Progress, Result>)

 TypeOfVarArgParams

 It contains information about what type of params used for execution.

 ProgressValue

 It contains information about progress units. While doing background operation we can update
information on UI using onProgressUpdate().

 ResultValue

 It contains information about result type.


DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
 For this let’s use the following permission and then design
the layout.

 To Access the web URLs we need to have a HTTPHandler


class which is as follows.
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP

 As the first step


in the activity
java class we
can define &
initialize relevant
variables.
DEVELOPING A WEB SERVICE CONSUMER APP
 We can get
the device
private IP
and as
follows
either using
WiFi or
Mobile
Data
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
 We can get the public IP address by calling to an AsyncTask.

 We can create GetPublciIP class as an inner class of our activity class as follows.

 We can override the onPreExecute Method of the GetMyPublicIP class as follows.


DEVELOPING A WEB SERVICE CONSUMER APP
 We can override the onPostExecute Method of the  We can override the doInBackground of the
GetMyPublicIP class as follows. GetMyPublicIP class as follows.
DEVELOPING A WEB SERVICE CONSUMER APP
 We can get the IP address related details by calling to an AsyncTask using the execute
method.

 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.

 We can override the onPostExecute Method of the GetIPDetails as follows.


DEVELOPING A WEB SERVICE CONSUMER APP
 We can override the doInBackground Method of the GetIPDetails class as follows.
DEVELOPING A WEB SERVICE CONSUMER APP
 Following is the full source code of the activity class.
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP
DEVELOPING A WEB SERVICE CONSUMER APP

You might also like