0% found this document useful (0 votes)
6 views

Android

The document provides an overview of various Android development concepts, including Android Virtual Devices (AVD), emulators, file formats (.apk vs .jar), virtual machines (JVM vs DVM), and the significance of Android in mobile app development. It explains UI components such as checkboxes, radio buttons, and progress bars, as well as the lifecycle of activities, services, and broadcasts. Additionally, it discusses JSON and XML parsing, their differences, and customization capabilities for maps in Android applications.

Uploaded by

bobjacob627
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Android

The document provides an overview of various Android development concepts, including Android Virtual Devices (AVD), emulators, file formats (.apk vs .jar), virtual machines (JVM vs DVM), and the significance of Android in mobile app development. It explains UI components such as checkboxes, radio buttons, and progress bars, as well as the lifecycle of activities, services, and broadcasts. Additionally, it discusses JSON and XML parsing, their differences, and customization capabilities for maps in Android applications.

Uploaded by

bobjacob627
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

ALAN MATHEW (YMBC - MAMS)

PH : +91 89217 23070

Write notes on a)Android Virtual Device (AVD) b) Android Emulators?


a) Android Virtual Device (AVD): Android Virtual Device (AVD) is an emulator
configuration that allows Android application developers to test their application on
different virtual devices. It provides a virtual environment to run the application,
simulating different configurations of devices, screen sizes, and hardware
specifications. The emulator runs the Android operating system in a virtual
environment, allowing the developers to test their apps on different versions of
Android. To create an AVD, the developer needs to use the Android Virtual Device
Manager (AVD Manager) in Android Studio. The AVD Manager provides various
configuration options to create an emulator, including the device type, screen size,
resolution, and Android version. Developers can create multiple AVDs with different
configurations to test their applications on various devices. b) Android Emulators:
Android Emulator is a software program that allows developers to test their Android
applications without a physical device. It is a virtual mobile device that mimics the
hardware and software features of a real mobile device. Emulators provide a way for
developers to test and debug their applications on different virtual devices without
requiring a physical device. Android Studio provides an emulator that simulates
different configurations of virtual devices, including different screen sizes,
resolutions, hardware specifications, and Android versions. Developers can use the
emulator to test their applications on different virtual devices, enabling them to
optimize their apps for a wide range of devices. Emulators can also be used to run
Android applications on desktop computers, allowing users to experience the app on
a larger screen. This is useful for testing and debugging the application, as well as for
demonstrating the app to clients or users.

Distinguish between a) .apk and .jar b) JVM and DVM


a) The main difference between .apk and .jar is that .apk is the file format used for
distributing and installing Android applications, while .jar is the file format used for
Java libraries and applications. An .apk file contains all the necessary files for an
Android application, including code, resources, and manifest. It is designed to be
installed on an Android device and is typically signed with a digital certificate. On
the other hand, a .jar file contains compiled Java classes, resources, and metadata. It
is used as a library or a component that can be used by other Java applications or
libraries. In summary, while both .apk and .jar contain compiled code, .apk is specific
to Android applications while .jar is a more general file format for Java libraries and
applications. b) JVM (Java Virtual Machine) and DVM (Dalvik Virtual Machine) are
both virtual machines used to run code in different environments. However, there are
some significant differences between the two: ● Language: JVM is designed to run
Java bytecode, while DVM is designed to run bytecode that is generated by the
Android SDK, which includes Java as well as other languages such as Kotlin. ●
Architecture: JVM is stack-based, while DVM is register-based. This means that
DVM uses a smaller instruction set and can execute code more efficiently. ● Memory
management: JVM uses a garbage collector to manage memory, while DVM uses a
combination of garbage collection and manual memory management. ● Performance:
DVM is optimized for mobile devices with limited resources, while JVM is designed
for desktop and server environments. This makes DVM more efficient and faster in
terms of performance in the context of Android. Overall, while JVM and DVM have
some similarities, they are designed for different purposes and have different
architectures and features.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Why is Android used in mobile application development?


Android is used in mobile application development for several reasons: ● Open
source: Android is an open-source operating system that is freely available to
developers. This means that developers can use the Android platform to create
innovative and unique mobile applications without having to pay any licensing fees. ●
Large user base: Android has a large user base, with over 2.5 billion active devices
worldwide. This means that there is a huge market for Android apps, making it an
attractive platform for developers. ● Easy to develop: Android provides a range of
tools and resources that make it easy for developers to create mobile applications. The
Android SDK includes a range of libraries, APIs, and development tools that simplify
the process of app development. ● Customizable: Android is highly customizable,
which allows developers to create unique and innovative mobile applications that can
be tailored to the specific needs of their users. ● Integration with other Google
services: Android integrates seamlessly with other Google services, such as Google
Maps, Google Drive, and Google Analytics, which can be useful for developers who
want to create mobile applications that rely on these services.
Explain the following with syntax and suitable examples: a) Custom toast alert b)
Time and date picker c) Image view and scroll view.
a) Custom Toast Alert: A toast is a small pop-up message that appears on the screen
to inform the user about some activity. A custom toast alert allows you to display a
customized message with a specific design or layout.
Syntax: Toast toast = Toast.makeText(context, message, duration);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setView(yourCustomView);
toast.show();
b) Time and Date Picker: A time and date picker allows the user to select a specific
date or time using a graphical interface. This can be useful in applications that require
users to schedule appointments or events.
Syntax:
// create a date picker dialog
DatePickerDialog datePickerDialog = new DatePickerDialog(context, listener, year,
month, day);
// create a time picker dialog
TimePickerDialog timePickerDialog = new TimePickerDialog(context, listener, hour,
minute, is24HourFormat);
c) Image View and Scroll View: An image view is a UI component that displays an
image on the screen. A scroll view is a container that allows the user to scroll through
a larger UI component that doesn't fit entirely on the screen.
Syntax: // create an image view ImageView
imageView = findViewById(R.id.imageView);
imageView.setImageResource(R.drawable.my_image);
// create a scroll view ScrollView
scrollView = findViewById(R.id.scrollView);
scrollView.addView(yourLargeUIComponent);
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Explain the following: a. Check Box b. Radio Button c. Radio Group d.Toggle
Button e. Progress Bar
a. Check Box: A checkbox is a UI component that allows the user to select one or
more options from a set of options. A checkbox has two states, checked and
unchecked, and the user can switch between these states by tapping on the checkbox.
In Android, a checkbox is implemented using the CheckBox class. The state of a
checkbox can be checked programmatically using the isChecked() method. b. Radio
Button: A radio button is a UI component that allows the user to select one option
from a set of mutually exclusive options. Radio buttons are usually used in a Radio
Group, which is a container that groups together multiple radio buttons. In Android, a
radio button is implemented using the RadioButton class. The state of a radio button
can be checked programmatically using the isChecked() method. c. Radio Group: A
radio group is a container that groups together multiple radio buttons. A radio group
ensures that only one radio button can be selected at a time, and all other radio buttons
in the group are deselected. In Android, a radio group is implemented using the
RadioGroup class. d. Toggle Button: A toggle button is a UI component that allows
the user to switch between two states, on and off, with a single tap. A toggle button
has a visual indicator that shows the current state, and the user can switch between the
states by tapping on the button. In Android, a toggle button is implemented using the
ToggleButton class. e. Progress Bar: A progress bar is a UI component that displays
the progress of a task that is being executed in the background. A progress bar has a
visual indicator that shows the progress of the task, and the user can see how much of
the task has been completed. In Android, a progress bar is implemented using the
ProgressBar class. The progress of a progress bar can be set programmatically using
the setProgress() method.

Explain activity in detail. b) Explain the use of intent with suitable programs.
a) Android Activity In Android, an activity is a fundamental component of an
application that represents a single screen with a user interface. An application can
have multiple activities, each representing a distinct user interaction within the app.
An activity provides a window for drawing the user interface and handles user
interactions such as button clicks, touch events, and keystrokes. It also manages the
lifecycle of the app, handling events such as when the app is started, paused, resumed,
and stopped. When an activity is launched, it is placed on the top of the activity stack,
and the user interacts with it until it is finished or the user navigates to another activity.
The Android system manages the activity stack, and activities can be launched and
closed dynamically based on user interactions or programmatic logic. Activities are
defined in the AndroidManifest.xml file, and each activity has a unique name and can
be launched by an intent. An activity can also pass data to another activity using intent
extras or receive data from another activity using startActivityForResult() method.
Overall, activities are a critical part of Android app development and provide the
foundation for creating interactive user interfaces and managing the lifecycle of an
application. b) Use of Intents Intents are used to communicate between the
components of an Android application, such as activities, services, and broadcast
receivers, as well as to communicate with other applications on the device. Intents are
used to initiate actions, pass data, and start activities. There are two types of intents:
explicit intents and implicit intents. Explicit intents are used to start a specific
component within the same application, whereas implicit intents are used to start a
component outside of the application.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Explain in detail Service and Broadcast life cycle with a neat diagram.
Service and Broadcast are two important components in the Android operating system
that allow developers to perform tasks in the background and respond to system
events respectively. Here is a detailed explanation of their life cycles:
Service Life Cycle:
● onCreate() - Called when the service is created. ● onStartCommand() - Called when
the service is started. ● onHandleIntent() - This method is called from
onStartCommand() and contains the actual code to be executed by the service. ●
onBind() - This method is called when a client wants to bind to the service. ●
onUnbind() - Called when all clients have unbound from the service. ● onDestroy() -
Called when the service is destroyed.
Broadcast Life Cycle:
● onReceive() - This method is called when the broadcast is received. ● setResult() -
Used to set the result of the broadcast. ● getResult() - Used to get the result of the
broadcast. ● abortBroadcast() - Used to abort the broadcast. ● setPriority() - Used to
set the priority of the broadcast receiver. ● isOrderedBroadcast() - Used to check if
the broadcast is ordered. ● getAbortBroadcast() - Used to check if the broadcast was
aborted.

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.

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.
try {
JSONObject jsonObject = new JSONObject(jsonString);
String name = jsonObject.getString("name");
int age = jsonObject.getInt("age");
JSONArray jsonArray = jsonObject.getJSONArray("hobbies");
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

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.
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();
}

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: John Doe [email protected] 123-456-7890
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
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

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.

Why is Android used in mobile applications?


Android is widely used for mobile application development due to its open-source
nature, flexibility, and compatibility with a wide range of devices. It provides an
extensive set of development tools, libraries, and frameworks that enable developers
to create innovative and engaging mobile applications. Additionally, Android offers a
large user base, which means there is a vast market for developers to reach out to with
their apps. Moreover, Android supports a variety of programming languages like Java,
Kotlin, and C++, making it easier for developers to write code. It also supports
various hardware features like touchscreens, accelerometers, and cameras, providing
ample opportunities to develop innovative mobile applications. Furthermore, Android
provides seamless integration with Google services such as Google Maps, Google
Drive, and Google Play, making it easier for developers to create and distribute their
apps.

Briefly explain Android Application Framework and its basic components.


Android Application Framework provides a set of pre-built tools and components that
developers can use to create Android applications. Its basic components include
Activities, Services, Broadcast Receivers, and Content Providers, which can be
combined to build various types of applications. Activities represent screens in the
application, and each screen is defined as an Activity in the application manifest file.
Services are used for background processing and can run even if the application is not
in the foreground. Broadcast Receivers listen for system events and respond
accordingly. Content Providers allow applications to share data and interact with each
other. The Android Application Framework provides a standardized approach to app
development and allows developers to focus on the logic and user interface of the
application rather than the underlying system components.

Table Layout with an example.


TableLayout is a ViewGroup in Android that arranges its child views in rows and
columns. Each row in a TableLayout is defined using a TableRow, and each cell or
column is defined using a child view of the TableRow.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Stakeholders of Android? Explain. The stakeholders of Android include various


groups of individuals and organizations involved in the development and use of the
Android platform. Some of the key stakeholders include: ● Google: As the developer
of the Android platform, Google is a major stakeholder in its success. Google is
responsible for providing updates, improvements, and new features to the Android
operating system. ● App developers: App developers are a critical stakeholder group
for Android, as they create the apps that run on the platform. Developers use Android
tools and APIs to build and distribute their apps on the Google Play Store and other
app stores. ● Device manufacturers: Device manufacturers such as Samsung, Oppo
and Xiaomi are also important stakeholders in Android. These companies produce
hardware that runs the Android operating system, and often customize it to fit their
own devices. ● Users: Android users are the ultimate stakeholders, as they are the
ones who use the platform to access apps and services on their mobile devices. User
feedback and usage patterns help shape the direction of the Android platform over
time.

List the responsibilities of ADT.


ADT (Android Development Tools) is a plugin for the Eclipse IDE that provides a
powerful, integrated environment for building Android apps. It extends the
capabilities of Eclipse to let you quickly set up new Android projects, create an
application UI, debug your apps using the Android SDK tools, etc. ADT's main
responsibilities are: ● Provide a powerful IDE for developing Android apps. ADT
includes a number of features that make it easy to develop Android apps, such as a
graphical layout editor, a debugger, and a code editor. ● Make it easy to create new
Android projects. ADT can create new Android projects with a few clicks, and it can
also import existing Android projects. ● Provide access to the Android SDK tools.
ADT includes a number of tools that can be used to develop Android apps, such as the
Android SDK Manager, the Android SDK Tools, and the Android SDK Emulator. ●
Help you debug your Android apps. ADT includes a debugger that can help you find
and fix bugs in your Android apps. ● Make it easy to generate signed APK files. ADT
can generate signed APK files that can be distributed to users.

Explain Relative Layout with Example.


Relative Layout is a view group in Android that allows you to position child views
relative to each other or relative to the parent. This is in contrast to Linear Layout,
which positions child views in a linear fashion from top to bottom. To use Relative
Layout, you first need to create a RelativeLayout object in your layout file. Then, you
can add child views to the RelativeLayout by specifying their ID and their position
relative to the parent or other child views. For example, you could add a button to the
top left of the parent view by using the following code:
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Explain any five attributes of Checkbox:


attributes of Checkbox in Android: ● android:checked: This attribute specifies
whether the checkbox is checked or not. If the checkbox is checked, the attribute will
have the value true. If the checkbox is unchecked, the attribute will have the value
false. ● android:drawable: This attribute specifies the drawable to use as the icon for
the checkbox. ● android:text: This attribute specifies the text to display next to the
checkbox. ● android:onClick: This attribute specifies the method to call when the
checkbox is clicked. ● android:visibility: This attribute specifies whether the
checkbox is visible or not. If the checkbox is not visible, the attribute will have the
value gone. If the checkbox is visible, the attribute will have the value visible.

Demonstrate the use of ArrayAdaptor in Spinner control with code.

Progress Bar with syntax and examples.


Progress Bar is a visual representation of the progress of a task. In Android, it is used
to indicate the progress of an operation, such as loading data or uploading a file. To
use a Progress Bar in your Android app, you need to add the ProgressBar view to your
layout XML file. You can customize the appearance of the Progress Bar using
attributes such as color, size, and style. Example:
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Java code:

image view and scroll view.


ImageView is a UI control in Android that allows developers to display an image in
their app. It can be used to display images from resources or from a web URL.
Developers can customize the size, scale type, and other attributes of the ImageView
to fit their app's needs. ScrollView is a UI control in Android that allows developers
to create a scrollable view when the content inside a layout is too large to fit on the
screen.
ScrollView can contain only one direct child element, but that child can be a complex
layout that contains multiple elements. Developers can also customize the scroll
behavior and appearance of the ScrollView using various attributes. Both ImageView
and ScrollView are widely used in Android app development for displaying images
and creating scrollable views respectively. By understanding their usage and
customization options, developers can create more engaging and user-friendly apps.

Why do we use Toast alert? Explain with an example.


Toast alerts are used to show a quick message to the user for a short duration of time,
typically less than 5 seconds. This is useful for providing the user with feedback or a
notification without interrupting their current task. For example, when the user clicks
on a button, a Toast alert can be displayed to show that the action has been completed.

In this example, we are creating a Toast alert with the message "Button Clicked" and
a duration of LENGTH_SHORT (which is usually 2-3 seconds). The
getApplicationContext() method is used to get the current context of the application,
and the show() method is used to display the Toast alert.

Explain intent. Explain how intents are created?


An Intent is an abstract messaging object that provides a way to communicate
between components such as activities, services, broadcast receivers, and content
providers. Intents are used to start or stop an activity, service, or broadcast receiver,
and pass data between them. Intents can be created using two constructors: explicit
and implicit. Explicit intents are used to start a specific component in the same
application, while implicit intents are used to start any component that can perform a
particular action regardless of the application. To create an intent, you first need to
specify its action, which is a string that identifies the action to be performed. Then,
you can add any additional data or extras to the intent, such as a URI or a bundle of
key-value pairs. Finally, you can use the startActivity() method to start the activity
associated with the intent.

Create an application that will pass one number to the next screen, and on the
next screen shows the double of that number.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

MainActivity.java:

SecondActivity.java:

Android multimedia framework architecture.


The Android multimedia framework architecture is a layered architecture that consists
of the following layers: ● Application layer: This layer is responsible for the user
interface of the multimedia application. It provides the views and controls that the
user uses to interact with the multimedia content. ● Media layer: This layer is
responsible for the playback and recording of multimedia content. It provides the
codecs and other components that are necessary to decode and encode multimedia
content. ● Hardware layer: This layer is responsible for the interaction with the
hardware. It provides the drivers and other components that are necessary to access
the multimedia hardware.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Write a java code to implement text to speech.


Java code to implement text to speech in Android:

This code creates a TextToSpeechManager class that initializes a TextToSpeech


object and sets the language to US English in the onInit method. The speak method
takes a string as input and speaks it using the TextToSpeech object, and the shutdown
method releases the resources used by the TextToSpeech object.

Briefly explain the functions i) onCreate() ii) onPause() iii) onDestroy() iv)
onStop()
i) onCreate() is a lifecycle method in Android that is called when an activity or
application is first created. It is used to initialize variables, set up UI elements, and
perform other necessary setup tasks. ii) onPause() is called when an activity is no
longer in the foreground and has lost focus. It is often used to save the state of the
activity, such as user input, so that it can be restored later when the activity comes
back into focus. iii) onDestroy() is called when an activity is being destroyed and
removed from memory. It is used to clean up any resources that were allocated by the
activity, such as unregistering listeners or releasing memory. iv) onStop() is called
when an activity is no longer visible to the user. It is often used to release resources
that are no longer needed while the activity is in the background, such as stopping a
media player or releasing a camera.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Write java and xml code to play an audio file.


Java Code:

XML Code:

What are the classes used to play Audio and Video in Android?
The classes used to play audio are MediaPlayer and AudioManager. MediaPlayer is a
class that can play various types of audio formats and provides various methods to
control the playback, such as start(), pause(), stop(), and release(). AudioManager is
used to control the volume and audio settings of the device. The class used to play
video in Android is VideoView. VideoView is a subclass of SurfaceView and
provides an easy way to play videos. It has built-in support for playing various types
of video formats and provides various methods to control the playback, such as start(),
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

pause(), stopPlayback(), and setVideoPath(). It also supports various video display


options, such as full screen and aspect ratio adjustments.

Explain different packages imported for Wi-fi activity.


There are several packages imported for Wi-Fi activity in Android, each with its own
set of functionalities. Some of the most commonly used packages are:
● android.net.wifi package provides classes to interact with Wi-Fi hardware, scan
networks, connect to a network, manage settings, and work with Wi-Fi Direct.
● android.net.wifi.p2p package provides classes for Wi-Fi Direct to discover nearby
devices, create groups, and establish connections for peer-to-peer communication in
apps like file sharing or multiplayer gaming. ● android.net.wifi.aware package
provides classes for Wi-Fi Aware to discover nearby devices, establish connections,
and exchange data without an access point.Developers can use these packages to build
Wi-Fi enabled apps on Android, whether they are simple or complex, as they offer a
range of tools and necessary functionality for connecting to Wi-Fi networks or
utilizing advanced Wi-Fi technologies like Wi-Fi Direct or Wi Fi Aware.

How do we setup SQLite database connection?


To set up a SQLite database connection in Android, first create a subclass of
SQLiteOpenHelper. Then override the onCreate() and onUpgrade() methods to create
the database and handle any upgrades. After that, create an instance of the
SQLiteOpenHelper class, passing in the context, database name, and version number,
and call the getWritableDatabase() or getReadableDatabase() method to obtain a
SQLiteDatabase object that can be used to perform database operations. Finally, use
the SQLiteDatabase object to perform operations like inserting, updating, and
querying data. When setting up a SQLite database connection, it is important to
properly handle errors, such as the database being locked, and to close the database
connection when it is no longer needed. Additionally, it is recommended to use
constants for column names and table names, to avoid typos and make it easier to
refactor the code in the future.

What is the need for BroadcastReceiver while scanning wi fi? BroadcastReceiver


is used to receive system-wide broadcasts or intents. When scanning Wi-Fi, the
BroadcastReceiver is required to receive Wi-Fi scan results through the intent. The
Wi-Fi scan results contain the list of available Wi-Fi access points, their signal
strengths, and other relevant information. The BroadcastReceiver allows the
application to register for specific intent filters and receive relevant broadcasts. When
the Wi-Fi scan results are ready, the system broadcasts the intent, which triggers the
onReceive() method of the registered BroadcastReceiver. The application can then
extract the relevant information from the intent and perform any necessary actions,
such as displaying the available Wi-Fi access points in a list or map view.

Explain sending SMS with an example.


Sending SMS in Android can be achieved using the SMS Manager class. To send an
SMS, we need to create an instance of the SMS Manager class and call its
sendTextMessage() method.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Here, we first obtain the instance of the SMS Manager using its getDefault() method.
Then, we define the recipient's phone number and message text. Finally, we call the
sendTextMessage() method, passing in the recipient's phone number, message text,
and other optional parameters. Note: To send SMS, the sender needs to add the
SEND_SMS permission to sender’s AndroidManifest.xml file.

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:


Example of a JSON array:

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.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

Write a java and xml code to delete the details of students from sqlite table
student(regno, name, address) whose regno is given.
First, create a layout file (delete_student_layout.xml) to input the registration number:

Next, create a Java activity class (DeleteStudentActivity.java) to handle the deletion


process:

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,
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

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

Write a java and xml code to save the details of student to sqlite table
student(regno, name, address).
Java code:

XML Code:
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

ANDROID ARCHITECTURE Mostly Android has 4 layers: 1.Applications


2.Application Framework 3.Libraries 4.Android Runtime 5.Linux Kernel
1. APPLICATIONS: ❖ All applications in this layer are written using Java. ❖ The
applications that an android device provide includes
• Email client • SMS programs • Maps • Browser • Calender • Contacts • Games etc
2. APPLICATION FRAMEWORKS: The Application Framework layer provides
many higher-level services to applications in the form of Java classes. Application
developers are allowed to make use of these services in their applications. The
Android framework includes the following key services − 1.Activity Manager −
Controls all aspects of the application lifecycle and provides a common backstack for
navigation. 2.Window manager- organizes the screen layout and locates the drawing
surface and performs other window related jobs 3.View Manager − An extensible set
of views used to create application user interfaces. 4.Content Providers − Allows
applications to publish and share data with other applications. 5.Notifications
Manager − Allows applications to display alerts and notifications to the user.
6.Package Manager- manages the other packages in the system 7.Telephony Manager-
to handle the receiver call or voice calls 8.Resource Manager − Provides access to
non-code embedded resources such as strings, color settings and user interface layouts.
ALAN MATHEW (YMBC - MAMS)
PH : +91 89217 23070

9.Location Manager-helps to locate the mobile device.example-GPS,Ex-map


10.XMPP Service Manager-Services like music,ringtone,browser etc managed here.
3.Linux kernel: • The entire Android OS is built on the top of Linux 2.6 with
architectural changes made by Google. • Offers better security and networking •
Android run time gives .dex file which goes to the linux kernel and calls the suitable
drivers so that it can communicate with the drivers. • Following are the drivers: •
Display drivers • Camera Drivers • Bluetooth driver • Flash memory driver • Usb
Driver • Power management driver • Keypad driver • Wifi driver etc
4.Libraries • Written in C and C++ libraries • This layer is communicated through
Java Native Interface package. • 9 major components ❑ Media library provides
support to play and record an audio and video formats. ❑ Surface manager
responsible for managing access to the display subsystem. ❑ SGL and OpenGL both
cross-language, cross-platform application program interface (API) are used for 2D
and 3D computer graphics. ❑ SQLite provides database support ❑ FreeType
provides font support. ❑ Web-Kit This open source web browser engine provides all
the functionality to display web content and to simplify page loading. ❑ SSL (Secure
Sockets Layer) is security technology to establish an encrypted link between a web
server and a web browser.
5.ANDROID RUN TIME • Android Runtime environment is one of the most
important part of Android. It contains components like core libraries and the Dalvik
virtual machine(DVM). • Mainly, it provides the base for the application framework
and powers our application with the help of the core libraries.
5.1 CORE LIBRARIES Different from java SE libraries, provides functionalities like
• data structure • file access • network access • Utilities • graphics etc
5.2 Dalvik Virtual Machine (DVM) Developed by Dan Bornstein of Google. • Like
Java Virtual Machine (JVM), Dalvik Virtual Machine (DVM) is a register-based
virtual machine and specially designed and optimized for android to ensure that a
device can run multiple instances efficiently. • Runs .dex files. These files are built
from .class files at compile time and provide higher efficiency in low resource
environments. • It depends on the layer Linux kernel for threading and low-level
memory management.

You might also like