0% found this document useful (0 votes)
8 views8 pages

Part A: 2020 March

Bachelor of Computer Application , Semester 6 ,Android
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Part A: 2020 March

Bachelor of Computer Application , Semester 6 ,Android
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Part A

Module 5 : Android

2020 March

11. Why is JSON more lightweight than XML?


JSON (JavaScript Object Notation) is more lightweight than XML (Extensible Markup
Language) in Android because it uses a simpler and more compact syntax to represent data,
making it more efficient to parse and transmit over the network. JSON uses key-value pairs
to represent data, while XML uses nested tags and attributes, making it more verbose and
complex. JSON is therefore a better choice for mobile apps that require fast and efficient
data transfer and processing.

12. How is the tracking of user location done in Android?


Android tracks user location using a combination of GPS, Wi-Fi, and mobile networks. It
collects location data through sensors in the device and sends it to Google servers, where it
is used to improve location-based services. Users can control and customize location
settings in the device settings menu.

2021 April

11. Why is JSON language independent?


JSON is language independent in Android because it uses a simple text format that can be
easily understood and generated by most programming languages. It does not rely on any
particular data model or programming language, making it easy to use and widely adopted in
many different programming environments.

12. What are the permissions required for setting up the Google
maps app in AndroidManifest.xml file?
To set up the Google Maps app in the AndroidManifest.xml file in Android, you need to add
the following permissions:

● INTERNET: to access the internet for downloading map tiles and other resources.
● ACCESS_NETWORK_STATE: to check if a network connection is available before
making any network requests.
● ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION: to determine the user's
current location for location-based services.
You may also need to add additional permissions depending on the features and
functionalities of your app that use Google Maps.

2022 April

11. Write the syntax of JSON.


Here's a small example of JSON syntax in Android:
{
"name": "John Smith",
"age": 30,
"city": "New York"
}
In this example, we have a JSON object that contains three key-value pairs: "name" with a
value of "John Smith", "age" with a value of 30, and "city" with a value of "New York". JSON
syntax uses curly braces to define objects and key-value pairs are separated by a colon,
while each pair is separated by a comma.

12. How do we identify the current user location?


To identify the current user location in Android, we can use the LocationManager class and
its requestLocationUpdates() method to receive periodic location updates. We can also use
the FusedLocationProviderClient class, which provides a simpler interface to retrieve
location data. Additionally, we can use Google Maps API or other third-party location
services to get the user's location.
Part B
Module 5 : Android

2020 March

21. Distinguish between JSON Array and JSON Object.


A JSON object is a collection of key/value pairs, while a JSON array is an ordered list of
values. JSON objects are surrounded by curly braces {}, while JSON arrays are surrounded
by square brackets [].

The key/value pairs in a JSON object can be of any data type, while the values in a JSON
array must be of the same data type. For example, a JSON object could have a key called
"name" with a value of "John Doe", while a JSON array could have a value of "123".

JSON objects are often used to store data about people, places, or things, while JSON
arrays are often used to store lists of data. For example, a JSON object could be used to
store information about a customer, such as their name, address, and phone number, while
a JSON array could be used to store a list of products that a store sells.

When working with JSON data in Android, you would use a JSONArray to parse JSON
which starts with the array brackets. Arrays in JSON are used to organize a collection of
related items (Which could be JSON objects).

2021 April

21. Write the syntax and rules of JSON with examples.


JSON (JavaScript Object Notation) is a lightweight data interchange format used to
exchange data between client and server applications. It is easy to read and write, and also
easy to parse and generate.

Here are the basic syntax rules for JSON in Android:

● Data is represented in key/value pairs, separated by a colon (:).


● Multiple key/value pairs are separated by commas (,).
● Data is enclosed in curly braces ({}) to denote an object.
● Data is enclosed in square brackets ([]) to denote an array.

Example of a JSON object:


{
"name": "John",
"age": 30,
"city": "New York"
}
Example of a JSON array:
[ { "name": "John", "age": 30, "city": "New York" }, {
"name": "Mary", "age": 25, "city": "Los Angeles" }]
To parse and generate JSON data in Android, the built-in JSONObject and JSONArray
classes are used. These classes provide methods for creating and manipulating JSON data.

2022 April

21. With the help of the java code, explain how maps can be
added to the app?
To add maps to an Android app using the Google Maps Android API. This involves adding
the API key to the app manifest file and dependencies to the app build.gradle file. After
integrating the API, a map fragment can be added to the app layout file and the GoogleMap
object can be obtained in Java code using the getMapAsync() method. Markers and other
elements can then be added to the map as required, with an example of how to add a
marker provided.

SupportMapFragment mapFragment = (SupportMapFragment)


getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(map -> {
LatLng location = new LatLng(37.7749, -122.4194);
map.addMarker(new MarkerOptions().position(location).title("San
Francisco")).showInfoWindow();
map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 10));
});
Part C
Module 5 : Android

2020 March

25. Illustrate various drawing and user interaction customization


capabilities on maps.
Android provides a powerful framework for integrating maps in applications. Here are some
of the drawing and user interaction customization capabilities of maps in Android:

● Custom Markers: You can customize the markers used to display points of interest
on the map, including their color, shape, and icon.

● Polygons and Polylines: You can draw polygons and polylines on the map to
highlight specific areas or routes. These can be customized with different colors,
widths, and styles.

● Info Windows: When the user clicks on a marker, an info window can be displayed
with additional information about the location. These can be customized with different
colors, fonts, and layouts.

● Map Styles: You can customize the look and feel of the map, including the colors,
fonts, and textures used to display different elements.

● Gestures: You can customize the gestures that the user can perform on the map,
such as panning, zooming, and rotating.

● Location Tracking: You can enable the user's current location to be displayed on
the map, and customize how it is displayed, such as with a marker or a blue dot.

● Street View: You can integrate Google Street View into your application, allowing the
user to explore a location in 360-degree panoramic views.

Here's some sample code for adding a marker with custom icon to the map:
// Get the map fragment
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);

// Get the map object


GoogleMap googleMap = mapFragment.getMap();
// Create a marker
MarkerOptions markerOptions = new MarkerOptions()
.position(new LatLng(37.7749, -122.4194))
.title("San Francisco")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker));

// Add the marker to the map


googleMap.addMarker(markerOptions);

In this code, we are creating a new marker with a custom icon and adding it to the map. The
icon is loaded from a drawable resource file called custom_marker. This code assumes
that you have already obtained a reference to the GoogleMap object and have set up the
map fragment in your layout file.

2021 April

25. Explain parsing JSON and XML.


In Android, parsing JSON and XML are the ways to retrieve data from a remote server or a
local file.

JSON Parsing:
To parse JSON, first, we need to retrieve the JSON data from the server using HTTP
requests. Once we have the JSON data, we can use the built-in JSONObject and
JSONArray classes to parse and extract the data. The JSONObject class is used to parse a
JSON object while the JSONArray class is used to parse a JSON array. We can then access
the data in the JSON object or array using the key-value pairs or index values.

Example:
try {
JSONObject jsonObject = new JSONObject(jsonString);
String name = jsonObject.getString("name");
int age = jsonObject.getInt("age");
JSONArray jsonArray = jsonObject.getJSONArray("hobbies");
for (int i = 0; i < jsonArray.length(); i++) {
String hobby = jsonArray.getString(i);
// do something with the hobby
}
}
catch (JSONException e) {
e.printStackTrace();
}
XML Parsing:
To parse XML, we can use the SAX parser or the DOM parser. The SAX parser is an event-
driven parser that reads the XML file sequentially and triggers events when it encounters the
opening or closing tags of an element. The DOM parser, on the other hand, reads the entire
XML file into memory and creates a tree-like structure that we can traverse to access the
data.

Example:
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new
StringReader(xmlString)));
NodeList nodeList = document.getElementsByTagName("person");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String name =
element.getElementsByTagName("name").item(0).getTextContent();
int age =
Integer.parseInt(element.getElementsByTagName("age").item(0).getTextCont
ent());
// do something with the name and age
}
}
}
catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}

In both cases, it is important to handle exceptions when parsing the data to avoid runtime
errors.

2022 April

25. Differentiate and compare between XML & JSON with


examples.
XML (eXtensible Markup Language) and JSON (JavaScript Object Notation) are two
common data interchange formats used in Android for representing and transferring data.
Both XML and JSON have their own strengths and weaknesses, and the choice between the
two depends on the specific use case.

XML: It is a markup language that uses tags to define elements and attributes to define
properties. XML is primarily used for storing and transporting data, such as in configuration
files, web services, and document formats.

Example:
<user>
<name>John Doe</name>
<email>[email protected]</email>
<phone>123-456-7890</phone>
</user>

JSON: It is a lightweight data interchange format that uses key-value pairs to represent data.
JSON is primarily used for exchanging data between a client and a server, such as in web
APIs and mobile applications.

Example:
{
"user": {
"name": "John Doe",
"email": "[email protected]",
"phone": "123-456-7890"
}
}

Differences between XML and JSON:

● Syntax: XML uses tags and attributes to define elements and properties, while JSON
uses key-value pairs. JSON has a simpler syntax compared to XML.
● Parsing: Parsing XML requires a lot of code, while parsing JSON is simpler and
faster.
● Data types: XML supports various data types such as text, numbers, and dates, while
JSON supports only a few data types such as strings, numbers, and booleans.
● Size: XML is larger in size compared to JSON, as it includes tags and attributes.

In summary, XML is best suited for storing and transporting data, while JSON is ideal for
exchanging data between a client and a server.

You might also like