2. Displaying Google Maps
• It is possible to display maps in Android applications.
• Android provides a built-in library called Google Maps Android API
that allows you to integrate Google Maps in your Android app.
• This API provides a set of tools for displaying maps, adding markers
and overlays, and interacting with the map.
3. Displaying Google Maps cont…
• To use the Google Maps Android API, you need to first obtain an API
key from the Google Cloud Console.
• Once you have your API key, you can add the Google Maps Android API
to your app by adding the following dependency to your app's
build.gradle file:
• Implementation 'com.google.android.gms:play-services-maps:17.0.0'
4. Displaying Google Maps cont…
the following permissions to your app's
• You also need to add
AndroidManifest.xml file:
• <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
• <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
5. Displaying Google Maps cont…
• To display the map in your app, you can add a MapView to your app's
layout file and initialize it in your app's activity or fragment.
• For example:
10. Web Services
• Web services are a collection of open-source protocols and standards
(SOAP, UDDI, REST, XML-RPC, etc.) that are useful for the exchange of
data between systems or applications.
• Web services are built on top of open standards such as TCP/IP, HTTP,
Java, HTML, and XML.
12. Web Services cont…
• A web service is basically required to provide interoperability, i.e.
connecting various applications.
• It allows different apps to communicate with each other and share
the data and services among themselves.
• Web services provide a standard for all the types of client applications
to invoke functions on every type of app server.
13. Web Services cont… Android Web
Services Components
• The web server architecture generally contains the following three
roles-
• Publisher: The publisher can be understood as a Service provider.
• The publisher is responsible for creating the web service and making
it available for the Clients.
14. Web Services cont… Android Web
Services Components
• Subscriber: The Subscriber is nothing but, the service requester.
• The Service requester is the one that needs to contact the web
service.
• The client application will contact through a client application.
• This Client application can be based on .Net or any language based
language.
15. Web Services cont… Android Web
Services Components
• Broker: The broker here is the application that provides access to the
UDDI.
• The UDDI stands for Universal Description Discovery and Integration.
• It enables the client application to locate the web service exactly.
16. Web Services cont… Android Web
Services Working
• The working mechanism of web services is given below:
• Publish: Publishers Publishing the web services means informing the
broker about its existence.
• It is done using the Broker’s interface to make is easily accessible to
the subscribers
17. Web Services cont… Android Web
Services Working
• Subscribe: The Subscriber will consult the broker to
published web service easily .
locate the
• Bind: Once the information regarding the web services is gained from
the broker, the subscriber can bind the web service.
18. Web Services cont…
Open-source protocols and standards
• The different open-source protocols and standards that are useful for the
exchange of data between systems or applications are discussed here:
• XML-RPC (Remote Procedure Call) is the most basic XML protocol to
exchange data between a wide variety of devices on a network.
• It uses HTTP to quickly and easily transfer data and communication other
information from client to server.
19. Web Services cont…
Open-source protocols and standards
• UDDI (Universal Description, Discovery, and Integration) is an XML-
based standard for detailing, publishing, and discovering web
services.
• It’s basically an internet registry for businesses around the world.
• The goal is to streamline digital transactions and e-commerce among
company systems.
20. Web Services cont…
Open-source protocols and standards
• SOAP (Simple Object Access Protocol), is an XML-based Web service
protocol to exchange data and documents over HTTP or SMTP (Simple
Mail Transfer Protocol).
• It allows independent processes operating on disparate systems to
communicate using XML.
21. Web Services cont…
Open-source protocols and standards
• REST (Representational state transfer), provides communication and
connectivity between devices and the internet for API-based tasks.
• Most RESTful services use HTTP as the supporting protocol.
22. Web Services cont… Characteristics of
Web Services
• Here are the following characteristics of Web Services:
• Interoperability:
• Web services allow various applications to talk to each other and share data and
services among themselves.
• For example, a VB or .NET application can talk to Java web services and vice versa.
• Web services are used to make the application platform and technology
independent.
23. Web Services cont… Characteristics of
Web Services
• XML-Based:
• Web services use XML at data representationand data transportation
layers.
• Using XML eliminates any networking, operating system, or platform
binding.
• Web services based applications are highly interoperable at their core
level.
24. Web Services cont… Characteristics of
Web Services
• Supports Document Exchange:
• One of the key advantages of XML is its generic way of representing
not only data, but also complex documents.
• These documents can be as simple as representing a current address,
or they can be as complex as representing a book or Request for
Quotation (RFQ).
25. Web Services cont… Characteristics of
Web Services
• Ability to be Synchronous or Asynchronous:
• In synchronous invocations, the client blocks and waits for the service to
complete its operation.
• Asynchronous operations allow a client to invoke a service and then execute
other functions.
• Asynchronous clients retrieve their result at a later point in time, while
synchronous clients receive their result when the service has completed.
26. Web Services cont… Characteristics of
Web Services
• Supports Remote Procedure Calls (RPCs):
• Web services allow clients to invoke procedures, functions, and methods
on remote objects using an XML-based protocol. Remote procedures
expose input and output parameters that a web service must support.
• Component development through Enterprise Java Beans (EJBs) and .NET
Components has increasingly become a part of architectures and
enterprise deployments over the past couple of years.
27. Web Services cont… Characteristics of
Web Services
• Standardized Protocol:
• Web services use standardized industry standard protocol for the
communication.
• All the four layers (Service Transport, XML Messaging, Service
Description, and Service Discovery layers) use well-defined protocols
in the web services protocol stack.
28. Web Services cont… Characteristics of
Web Services
• Low Cost Communication:
• Web services use SOAP over HTTP protocol, so you can use your
existing low-cost internet for implementing web services.
• Besides SOAP over HTTP, web services can also be implemented on
other reliable transport mechanisms like FTP.
30. Threading
• Thread is a lightweight sub-process that provides us a way to do
background operations without interrupting the User Interface (UI).
• When an app is launched, it creates a single thread in which all app
components will run by default.
• The thread which is created by the runtime system is known as the
main thread.
31. Threading cont…
• The main thread’s primary role is to handle the UI in terms of event
handling and interaction with views in the UI.
• If there is a task that is time-consuming and that task is run on the
main thread, then it will stop other tasks until it gets completed, which
in turn may result in displaying a warning “Application is unresponsive”
to the user by the operating system.
32. Threading cont…
• So we need different threads for such tasks.
• As you can see the following image, showing threads
different tasks over main thread and background thread also:
handling
34. Threading cont…
• In android, all threading components belong to one of two basic
categories.
• 1- Threads that are attached to an activity/fragment: This category
of threads are bound to the lifecycle of the activity/fragment and
these are terminated as soon as the activity/fragment is destroyed.
• Thread components: AsyncTask, Loaders.
35. Threading cont…
• 2- Threads that aren’t attached to any activity/fragment: These
types of threads can continue to run beyond the lifetime of the
activity or fragment from which they were spawned.
• Threading Components: Service.
36. Threading cont…
Attached to an activity/fragment: ASYNCTASK
• AsyncTask is the most elementary Android component for threading.
• It’s super easy and simple to use it’s also good for some basic
scenarios:
38. Threading cont…
Attached to an activity/fragment: ASYNCTASK
• AsyncTask, however, falls short if you would like your deferred task to
run beyond the lifetime of the activity/fragment.
• The fact that even the slightest of screen rotation can cause the
activity to be destroyed is simply awful!
• So We Come to Loaders:
39. Threading cont…
Attached to an activity/fragment: LOADERS
• Loaders are the answer to the awful nightmare mentioned above.
• Loaders are great at performing in that context and they
automatically stop when the activity is destroyed, even more, the
sweet fact is that they also restart themselves after the activity is
recreated.
41. Threading cont…
Not attached to an activity/fragment: SERVICE
• Service could be thought of as a component that’s useful for
performing long (or potentially long) operations with no UI.
• Service’s don’t have any UI.
• Service runs within the main thread of its hosting process; the service
doesn’t create its own thread and doesn’t run during a separate
process unless you specify otherwise.
43. Threading cont…
Not attached to an activity/fragment: SERVICE
• Service could be thought of as a component that’s useful for
performing long (or potentially long) operations with no UI.
• Service’s don’t have any UI.
• Service runs within the main thread of its hosting process; the service
doesn’t create its own thread and doesn’t run during a separate
process unless you specify otherwise.
44. Threading cont…
Not attached to an activity/fragment: SERVICE
• Service could be thought of as a component that’s useful for
performing long (or potentially long) operations with no UI.
• Service’s don’t have any UI.
• Service runs within the main thread of its hosting process; the service
doesn’t create its own thread and doesn’t run during a separate
process unless you specify otherwise.
45. Threading cont…
• There are five types of thread used in Android mobile development:
1. Main Thread
2. UI Thread
3. Worker Thread
4. Any Thread
5. Binder Thread
46. Threading cont… Main Thread
• When we launch our app on Android, it creates the first thread of
execution called the “Main Thread”.
• The communication between the components from the Android UI
toolkit and the dispatching of events to their appropriate UI widgets is
handled by the main thread.
47. Threading cont… Main Thread
• We should avoid network operations, database calls, and the loading of
certain components in the main thread.
• Because the main thread is called synchronously when executed, that
means the user interface will remain completely unresponsive until the
performance completes.
49. Threading cont… UI Thread
• Every app in Android has its own thread which is responsible for
running the UI objects, like view objects.
• Such a thread is known as the UI thread.
• The UI thread is the main thread of execution for our app as this is
where most of the app code is run.
50. Threading cont… UI Thread
• The UI thread is where all of our app components (like activities,
services, content providers, and broadcast receivers) are created.
• This thread allows our tasks to perform their background work and
then move the results to UI elements such as bitmaps.
• All objects running on our UI thread will be able to access other
objects which are also running on the same UI thread.
51. Threading cont… UI Thread
• The tasks that we run on a thread from a thread pool do not run on
our UI thread, so they will not have access to UI objects.
• The data moves from a background thread to the UI thread, using a
handler that runs on the UI thread.
52. Threading cont…
The Worker Thread
• The worker thread is a background thread.
• The worker threads are created separately, other than threads like the
UI thread.
• As we know from the rules, we cannot block a UI thread so this is
where the worker thread comes into play since we can use them to
run the child processes and tasks.
53. Threading cont… Any Thread
• In Any thread, the annotated method can be called from any thread.
• If the annotated element is a class, then all methods in the class can
be called from Any Thread.
55. Threading cont… Binder Thread
• Binder thread represents a separate thread of service.
• The binder is a mechanism that provides inter-process communication.
• The binder thread is used in service binding with interprocess
communication.
• This concept is mainly related to service calls with interfaces defined by
Android Interface Definition Language (AIDL).