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

Android Application Development

The document discusses several key topics in Android application development: 1. Delegation in Kotlin allows classes and functions to allocate authority to other objects, allowing inheritance and implementations to be altered. There are explicit and implicit forms of delegation. 2. Ranges in Kotlin define sequences of values between endpoints using operators like (..) and functions like rangeTo() and downTo(). Ranges are commonly used in loops and conditionals. 3. An Android activity's lifecycle passes through stages like active, paused, stopped, and destroyed. Lifecycle callback methods like onCreate(), onStart(), onResume(), etc. notify the activity of state changes.

Uploaded by

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

Android Application Development

The document discusses several key topics in Android application development: 1. Delegation in Kotlin allows classes and functions to allocate authority to other objects, allowing inheritance and implementations to be altered. There are explicit and implicit forms of delegation. 2. Ranges in Kotlin define sequences of values between endpoints using operators like (..) and functions like rangeTo() and downTo(). Ranges are commonly used in loops and conditionals. 3. An Android activity's lifecycle passes through stages like active, paused, stopped, and destroyed. Lifecycle callback methods like onCreate(), onStart(), onResume(), etc. notify the activity of state changes.

Uploaded by

ROHIT MALLAH
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 82

Android Application Development

Q1. Delegation in Kotlin.


Ans: Delegation controls the allocation of
power/authority from an instance to another for any
object. For classes and functions implementations,
delegations can be used on static as well as mutable
relations between them.
Inheritance implementation in classes and functions
can be altered with the help of delegation techniques
and object-oriented programming languages support
it innately without any boilerplate code. Delegation is
used in Kotlin with the help of “by” keyword.
There are two types of delegation present in Kotlin:
 Explicit delegation: Supported by all object-
oriented language and it is done by passing a
delegate(the one to be implemented) object to
delegating object (the one that will implement
delegate object).
 Implicit delegation: Requires language-level
support for the delegation pattern.
Example of delegation:
interface delegation
{
fun mymessage()
fun mymessageline()
}

class delegationimplementation(val y: String) : delegation


{
override fun mymessage()
{
print(y)
}
override fun mymessageline()
{
println(y)
}
}

class Newfeature(m: delegation) : delegation by m


{
override fun mymessage()
{
print("Hello World")
}
}
// Main function
fun main()
{
val b = delegationimplementation("\nWelcome, World!")

Newfeature(b).mymessage()
Newfeature(b).mymessageline()
}

Q2. Ranges in Kotlin.


Ans: In Kotlin, the range is a collection of finite
values which is defined by endpoints. Ranges are
useful in programming to express sequences of
numbers easily.
They’re often used in loops or conditionals when you
need to work with a series of values in a specific
order.
The range in Kotlin consists of a start, a stop, and
the step.
The start and stop are inclusive in the Range and the
value of step is by default 1. The range is used with
comparable types.
These are the ways for creating Range in Kotlin –
 Using (..) operator: It is the simplest way to
work with range. It will create a range from the
start to end including both the values of start
and end. It is the operator form of rangeTo()
function.
val range = 1..5 // Creates a range from 1 to 5 (inclusive)

 Using rangeTo() function: It is similar to (..)


operator. It will create a range upto the value
passed as an argument.
val range = 1.rangeTo(5) // Creates a range from 1 to 5 (inclusive)

 Using downTo() function: It is reverse of the


rangeTo() or (..) operator. It creates a range in
descending order, i.e. from bigger values to
smaller value.
val descendingRange = 5.downTo(1) // Creates a range from 5 to 1
(inclusive)

 Specifying step in a range: With keyword step,


one can provide step between values. It is mainly
used in order to provide the gap between the two
values in rangeTo() or downTo() or in (..)
operator. The default value for step is 1 and the
value of step function cannot be 0.
val rangeWithStep = 1..10 step 2 // Creates a range from 1 to 10
(inclusive)

 Checking range membership: You can check if a


value is within a range using ‘in’ keyword.
val number = 3
if(number in 1..5) {
println(“$number is in the range from 1 to 5”)
}

Q3. Activity Life Cycle


Ans: In Android, an activity is referred to as one
screen in an application. It is very similar to a single
window of any desktop application. An Android app
consists of one or more screens or activities.
Each activity goes through various stages or a
lifecycle and is managed by activity stacks. So when a
new activity starts, the previous one always remains
below it. There are four stages of an activity.
1. If an activity is in the foreground of the
screen i.e at the top of the stack, then it is
said to be active or running. This is usually the
activity that the user is currently interacting
with.
2. If an activity has lost focus and a non-full-
sized or transparent activity has focused on
top of your activity. In such a case either
another activity has a higher position in multi-
window mode or the activity itself is not
focusable in the current window mode. Such
activity is completely alive.
3. If an activity is completely hidden by another
activity, it is stopped or hidden. It still retains
all the information, and as its window is hidden
thus it will often be killed by the system when
memory is needed elsewhere.
4. The system can destroy the activity from
memory by either asking it to finish or simply
killing its process. When it is displayed again to
the user, it must be completely restarted and
restored to its previous state.
For each stage, android provides us with a set of 7
methods that have their own significance for each
stage in the life cycle.
1. onCreate(): It is called when the activity is first
created. This is where all the static work is done
like creating views, binding data to lists, etc.
This method also provides a Bundle containing its
previous frozen state, if there was one.
2. onStart(): It is invoked when the activity is visible
to the user. It is followed by onResume() if the
activity is invoked from the background. It is
also invoked after onCreate() when the activity
is first started.
3. onRestart(): It is invoked after the activity has
been stopped and prior to its starting stage and
thus is always followed by onStart() when any
activity is revived from background to on-
screen.
4. onResume(): It is invoked when the activity
starts interacting with the user. At this point,
the activity is at the top of the activity stack,
with a user interacting with it. Always followed
by onPause() when the activity goes into the
background or is closed by the user.
5. onPause(): It is invoked when an activity is going
into the background but has not yet been killed.
It is a counterpart to onResume(). When an
activity is launched in front of another activity,
this callback will be invoked on the top activity
(currently on screen).
6. onStop(): It is invoked when the activity is not
visible to the user. It is followed by onRestart()
when the activity is revoked from the
background, followed by onDestroy() when the
activity is closed or finished, and nothing when
the activity remains on the background only.
7. onDestroy(): The final call received before the
activity is destroyed. This can happen either
because the activity is finishing (when finish() is
invoked) or because the system is temporarily
destroying this instance of the activity to save
space.

Q4. Coroutines in Kotlin.


Ans: Coroutines are a way to write code that can do
multiple things at once without making the program
complicated.
How to Use Coroutines in Kotlin:
You need a special library in Kotlin to use coroutines.
You can add this library to your project.
You use something called a "Coroutine Scope" to
start and manage coroutines. Think of it like a special
space for your coroutines to live.
Important Concepts:
Some functions in coroutines are special, marked
with the word suspend. It means these functions can
pause and let other things happen while they wait.
You launch coroutines using different commands, like
launch for basic tasks, async for tasks that give you
results, and runBlocking for testing.
Working with Threads:
Coroutines have something called "Dispatchers" that
help control where the code runs.
Structured Way of Doing Things:
There's a good way to organize your coroutines to
make sure they start and stop properly. It's like
making sure everything is neat and tidy.
Handling Problems:
Just like in regular code, things might go wrong. You
can use try and catch to deal with problems and keep
your program running smoothly.
In simpler terms, coroutines help you write code that
can do many things at the same time without making
your program hard to understand.
They have special rules and tools to make this
happen, like different types of coroutines for
different jobs and ways to organize them neatly.
A coroutine is an instance of a suspendable
computation. It is conceptually similar to a thread, in
the sense that it takes a block of code to run that
works concurrently with the rest of the code.
However, a coroutine is not bound to any particular
thread. It may suspend its execution in one thread
and resume in another one.
Coroutines can be thought of as light-weight threads,
but there is a number of important differences that
make their real-life usage very different from
threads.

Q5. Components of an Android Application.


Ans: There are some necessary building blocks that an
Android application consists of. These loosely coupled
components are bound by the application manifest
file which contains the description of each
component and how they interact. The manifest file
also contains the app’s metadata, its hardware
configuration, and platform requirements, external
libraries, and required permissions. There are the
following main components of an android app:
1. Activities:
Activities are said to be the presentation layer of
our applications. The UI of our application is built
around one or more extensions of the Activity class.
By using Fragments and Views, activities set the
layout and display the output and also respond to the
user’s actions. An activity is implemented as a
subclass of class Activity.
2. Services:
Services are like invisible workers of our app. These
components run at the backend, updating your data
sources and Activities, triggering Notification, and
also broadcast Intents. They also perform some
tasks when applications are not active. A service can
be used as a subclass of class Service.
3. Content Providers:
It is used to manage and persist the application data
also typically interacts with the SQL database. They
are also responsible for sharing the data beyond the
application boundaries. The Content Providers of a
particular application can be configured to allow
access from other applications, and the Content
Providers exposed by other applications can also be
configured. A content provider should be a sub-class
of the class ContentProvider.
4. Broadcast Receivers:
They are known to be intent listeners as they enable
your application to listen to the Intents that satisfy
the matching criteria specified by us. Broadcast
Receivers make our application react to any received
Intent thereby making them perfect for creating
event-driven applications.
5. Intents:
It is a powerful inter-application message-passing
framework. They are extensively used throughout
Android. Intents can be used to start and stop
Activities and Services, to broadcast messages
system-wide or to an explicit Activity, Service or
Broadcast Receiver or to request action be
performed on a particular piece of data.
6. Widgets:
These are the small visual application components
that you can find on the home screen of the devices.
They are a special variation of Broadcast Receivers
that allow us to create dynamic, interactive
application components for users to embed on their
Home Screen.
7. Notifications:
Notifications are the application alerts that are used
to draw the user’s attention to some particular app
event without stealing focus or interrupting the
current activity of the user. They are generally used
to grab user’s attention when the application is not
visible or active, particularly from within a Service or
Broadcast Receiver. Examples: E-mail popups,
Messenger popups, etc.

Q6. Android Architecture


Ans: Android architecture contains different number
of components to support any android device needs.
Android software contains an open-source Linux
Kernel having collection of number of C/C++ libraries
which are exposed through an application framework
services.
Among all the components Linux Kernel provides main
functionality of operating system functions to
smartphones and Dalvik Virtual Machine (DVM)
provide platform for running an android application.
The main components of android architecture are
following:-
 Applications: Applications is the top layer of
android architecture. The pre-installed
applications like home, contacts, camera, gallery
etc and third party applications downloaded from
the play store like chat applications, games etc.
will be installed on this layer only. It runs within
the Android run time with the help of the
classes and services provided by the application
framework.
 Application Framework: Application Framework
provides several important classes which are
used to create an Android application. It
provides a generic abstraction for hardware
access and also helps in managing the user
interface with application resources. Generally,
it provides the services with the help of which
we can create a particular class and make that
class helpful for the Applications creation. It
includes different types of services activity
manager, notification manager, view system,
package manager etc. which are helpful for the
development of our application according to the
prerequisite.
 Android Runtime: 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. 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.
 Platform Libraries: The Platform Libraries
includes various C/C++ core libraries and Java
based libraries such as Media, Graphics, Surface
Manager, OpenGL etc. to provide a support for
android development.
1. Media library provides support to play and
record an audio and video formats.
2. Surface manager responsible for managing
access to the display subsystem.
3. SGL and OpenGL both cross-language, cross-
platform application program interface (API)
are used for 2D and 3D computer graphics.
4. SQLite provides database support and
FreeType provides font support.
5. Web-Kit This open source web browser
engine provides all the functionality to
display web content and to simplify page
loading.
6. SSL (Secure Sockets Layer) is security
technology to establish an encrypted link
between a web server and a web browser.
 Linux Kernel: Linux Kernel is heart of the
android architecture. It manages all the available
drivers such as display drivers, camera drivers,
Bluetooth drivers, audio drivers, memory drivers,
etc. which are required during the runtime. The
Linux Kernel will provide an abstraction layer
between the device hardware and the other
components of android architecture. It is
responsible for management of memory, power,
devices etc.

Q7. What is Layout and its types.


Ans: Android Layout is used to define the user
interface that holds the UI controls or widgets that
will appear on the screen of an android application or
activity screen. Generally, every application is a
combination of View and ViewGroup. As we know, an
android application contains a large number of
activities and we can say each activity is one page of
the application. So, each activity contains multiple
user interface components and those components are
the instances of the View and ViewGroup. All the
elements in a layout are built using a hierarchy of
View and ViewGroup objects.
There are different types of Android Layout. Some
of them are as follows-
1. Relative Layout: The relative layout is used
to arrange the child views in a proper order
which means arranging the child objects
relative to each other.
Generally, if we create an application using a
linear layout that consists of 5 buttons. Even
if we specify weight and gravity properties
they will not be relatively arranged.
To arrange them in a proper order we need to
use the relative layout. To arrange them we
need some advanced properties.
Basically, we use layout_width, layout_height,
layout_text properties while creating an
application using the linear layout. But we need
some more advanced properties which are
supported by relative layout. There are so
many properties that are supported by relative
layout. some of the most used properties are
listed below:
->layout_alignParentTop
->layout_alignParentBottom
->layout_alignParentRight
->layout_alignParentLeft
->layout_centerHorozontal
->layout_centerVertical
->layout_above
->layout_below
Example:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dpl"
android:paddingRight="10dp">
</RelativeLayout>

2. Linear Layout: LinearLayout is the most basic


layout in android studio, that aligns all the
children sequentially either in a horizontal
manner or a vertical manner by specifying the
android:orientation attribute. If one applies
android:orientation=”vertical” then elements
will be arranged one after another in a vertical
manner and If you apply
android:orientation=”horizontal” then elements
will be arranged one after another in a
horizontal manner.
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
</LinearLayout>
3. Constraint Layout: ConstraintLayout is a layout
manager for Android that allows you to create
complex layouts with a flat view hierarchy. It
allows you to position and size UI elements
(such as buttons, text views, images) relative
to other elements or parent container using
constraints. This makes it easier to create
responsive and flexible user interfaces that
adapt well to different screen sizes and
orientations.

Q8. Content Provider in Android.


Ans: In Android, Content Providers are a very
important component that serves the purpose of a
relational database to store the data of applications.
The role of the content provider in the android
system is like a central repository in which data of
the applications are stored, and it facilitates other
applications to securely access and modifies that
data based on the user requirements. Android system
allows the content provider to store the application
data in several ways. Users can manage to store the
application data like images, audio, videos, and
personal contact information by storing them in
SQLite Database, in files, or even on a network. In
order to share the data, content providers have
certain permissions that are used to grant or
restrict the rights to other applications to interfere
with the data.
Operations in Content Provider:
Four fundamental operations are possible in Content
Provider namely Create, Read, Update, and Delete.
These operations are often termed as CRUD
operations.
1. Create: Operation to create data in a content
provider.
2. Read: Used to fetch data from a content
provider.
3. Update: To modify existing data.
4. Delete: To remove existing data from the
storage.
Working of the Content Provider:
UI components of android applications like Activity
and Fragments use an object CursorLoader to send
query requests to ContentResolver. The
ContentResolver object sends requests (like create,
read, update, and delete) to the ContentProvider as a
client. After receiving a request, ContentProvider
process it and returns the desired result. Below is a
diagram to represent these processes in pictorial
form.
Creating a Content Provider:
Following are the steps which are essential to follow
in order to create a Content Provider:
1. Create a class in the same directory where the
that MainActivity file resides and this class
must extend the ContentProvider base class.
2. To access the content, define a content
provider URI address.
3. Create a database to store the application
data.
4. Implement the six abstract methods of
ContentProvider class.
5. Register the content provider in
AndroidManifest.xml file using <provider> tag.

Q9. Broadcaster Receiver in Android.


Ans: Broadcast in android is the system-wide events
that can occur when the device starts, when a
message is received on the device or when incoming
calls are received, or when a device goes to airplane
mode, etc. Broadcast Receivers are used to respond
to these system-wide events. Broadcast Receivers
allow us to register for the system and application
events, and when that event happens, then the
register receivers get notified. There are mainly two
types of Broadcast Receivers:

 Static Broadcast Receivers: These types of


Receivers are declared in the manifest file and
works even if the app is closed.
 Dynamic Broadcast Receivers: These types of
receivers work only if the app is active or
minimized.
There are some static fields defined in the Intent
class which can be used to broadcast different
events. We have taken a change of airplane mode as a
broadcast event, but there are many events for
which broadcast register can be used. Following are
some of the important system-wide generated
intents:-
Description Of
Event
Intent

Indicates low battery


android.intent.action.BATTERY_LOW : condition on the
device.

This is broadcast once


android.intent.action.BOOT_COMPLETED after the system has
finished booting

To perform a call to
android.intent.action.CALL someone specified by
the data

Indicates that the date


android.intent.action.DATE_CHANGED
has changed

Indicates that the


android.intent.action.REBOOT device has been a
reboot

The mobile network or


android.net.conn.CONNECTIVITY_CHANGE wifi connection is
changed(or reset)

This indicates that


airplane mode has
android.intent.ACTION_AIRPLANE_MODE_CHANGED
been switched on or
off.

Q10. Lifecycle of Android Services.


Ans: In android, services have 2 possible paths to
complete its life cycle namely Started and Bounded.

1. Started Service (Unbounded Service):


By following this path, a service will initiate when an
application component calls the startService()
method. Once initiated, the service can run
continuously in the background even if the component
is destroyed which was responsible for the start of
the service. Two option are available to stop the
execution of service:
 By calling ‘stopService()’ method,
 The service can stop itself by using ‘stopSelf()’
method.
2. Bounded Service:
It can be treated as a server in a client-server
interface. By following this path, android application
components can send requests to the service and can
fetch results. A service is termed as bounded when
an application component binds itself with a service
by calling bindService() method. To stop the
execution of this service, all the components must
unbind themselves from the service by using
unbindService() method.
Q11. ‘this’ expression in Kotlin.
Ans: In Kotlin, the ‘this’ keyword refers to the
current receiver of the function or the current
instance of the class. Its meaning depends on the
context in which it is used.
1. In a member of a class:
When you are inside a class, the ‘this’ keyword
refers to the current object of that class. So, if
you’re writing code inside a method or property of
a class, and you use ‘this’, it means you are
referring to the instance of the class that the
method or property is being called on.
class MyClass {
fun myMethod() {
//Inside this method, “this” refers to the current instance of the class.

println(this.toString())
}
}

2. Extension Function:
Think of an extension function like a superpower
you give to a type (like a superhero gaining a new
ability). When you define an extension function,
you’re saying, “Hey, I want to give this extra ability
to this type of object”. So, when you use that
ability (call the function), the ‘this’ keyword inside
the function refers to the object you’re using it on.
fun String.addGreeting() : String {
return “Hello, $this!”
}
val greeting = “World”.addGreeting()
println(greeting)

Here, ‘this’ inside the ‘addGreeting’ function refers


to the specific ‘String’ instance (“World” in this
case).
3. No Qualifiers (“this” by itself):
When you say “this” without any extra information,
you’re talking about the things in the room you’re
currently in (the innermost room). It’s like saying,
“I’m dealing with the stuff right here, in this
room.”
class House {
fun doSomething() {
println(this.toString())
}
}
In this example, ‘this’ inside the ‘doSomething’
method refers to the specific ‘House’ instance.
4. Label Qualifiers for Outer Scope:
Now, imagine you are in Room B, which is inside
Room A. If you want to refer to something in Room
A when you’re in Room B, you might need to say
explicitly, “I’m talking about the things in Room A.”
In programming terms, you use label qualifiers to
do this.
class House {
inner class Room {
fun doSomething() {
println(this.toString())
println([email protected]())
}
}
}

In this example, ‘this’ inside the ‘doSomething’


method refers to the specific ‘Room’ instance, and
‘this@House’ refers to the outer ‘House’ instance.
In simple terms, when you say “this”, you’re usually
talking about the things in the current room(scope).
If you need to talk about something in a different
room (outer scope), you might need to use a special
way of specifying that room, like saying “this@Room”
to refer to the outer context.

Q12. RecyclerView in Android.


Ans: The RecyclerView is a flexible and efficient way
to display lists and grids of data. It's an
improvement over the older ListView and GridView
components because it allows for better performance
and more flexibility in how items are displayed and
animated.
Why use RecyclerView?
One of the cool features of RecyclerView is that it
doesn’t waste resources. When an item in the list is
not currently visible on the screen, instead of
throwing it away, RecyclerView cleverly keeps it in a
pool. So, when a new item needs to be displayed, it
just grabs one from the pool and updates it with the
new data. This recycling process helps in making your
app more efficient and responsive.
How does it Work?
Let’s say you’re scrolling through a list of photos. As
you scroll down, the photos you’ve already seen move
off the screen. In older approaches, these photos
would be completely discarded. But with
RecyclerView, they are kept in a reusable pool. So,
when you scroll back up, instead of creating new
views, it simply reuses the ones you’ve already seen.
Benefits:
1. Performance Improvement: RecyclerView is
more efficient in handling long lists compared
to its predecessor, ListView.
2. Resource Efficiency: By recycling views, it
reduces the need to crate new views, saving
system resources.
3. Power Consumption: Recycling Views also helps
in reducing power consumption, making your
app more battery-friendly.

Q13. Styles and Themes in Kotlin.


Ans: Styles:
A style is defined in an XML resource that is
separate from the XML that specifies the layout.
This XML file resides under res/values/ directory of
your project and will have <resources> as the root
node which is mandatory for the style file. The name
of the XML file is arbitrary, but it must use the .xml
extension.
You can define multiple styles per file using <style>
tag but each style will have its name that uniquely
identifies the style. Android style attributes are set
using <item> tag as shown below –
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomFontStyle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:capitalize">characters</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">12pt</item>
<item name="android:textColor">#00FF00</item>/>
</style>
</resources>

Themes:
A theme is nothing but an Android style applied to an
entire Activity or application, rather than an
individual View.
Thus, when a style is applied as a theme, every View
in the Activity or application will apply each style
property that it supports. For example, you can apply
the same CustomFontStyle style as a theme for an
Activity and then all text inside that Activity will
have green monospace font.
To set a theme for all the activities of your
application, open the AndroidManifest.xml file and
edit the <application> tag to include the
android:theme attribute with the style name. For
example –
<application android:theme="@style/CustomFontStyle">

But if you want a theme applied to just one Activity


in your application, then add the android:theme
attribute to the <activity> tag only. For example −
<activity android:theme="@style/CustomFontStyle">

There are number of default themes defined by


Android which you can use directly or inherit them
using parent attribute as follows −

<style name="CustomTheme" parent="android:Theme.Light">


...
</style>

Q14. Fragments in Android.


Ans: A fragment is like a modular piece of your app.
It’s a part of the user interface, but it’s not a whole
screen. Think of it as a building block. Instead of
having one big screen, you can have multiple
fragments on the same screen, kind of like putting
LEGO pieces together to create something awesome.
Why Use Fragments?
1. Flexibility:
Fragments are like building blocks that can be
combined in different ways, making your app
adaptable to various screen sizes.
2. Reusability:
You can use fragments in different parts of your
app, which is handy for consistency.
3. Responsive UI:
Fragments help in creating responsive user
interface that work well on both phones and
tablets.
Types of Fragments:
 Single frame fragments : Single frame
fragments are using for hand hold devices like
mobiles, here we can show only one fragment
as a view.
 List fragments : fragments having special list
view is called as list fragment
 Fragments transaction : Using with fragment
transaction. we can move one fragment to
another fragment.
Fragment Life Cycle:

onAttach() : The fragment instance is associated


with an activity instance. The fragment and the
activity is not fully initialized. Typically you get in
this method a reference to the activity which uses
the fragment for further initialization work.
onCreate() : The system calls this method when
creating the fragment. You should initialize essential
components of the fragment that you want to retain
when the fragment is paused or stopped, then
resumed.
onCreateView() : The system calls this callback when
it’s time for the fragment to draw its user interface
for the first time. To draw a UI for your fragment,
you must return a View component from this method
that is the root of your fragment’s layout. You can
return null if the fragment does not provide a UI.
onActivityCreated() : The onActivityCreated() is
called after the onCreateView() method when the
host activity is created. Activity and fragment
instance have been created as well as the view
hierarchy of the activity.
onStart() : The onStart() method is called once the
fragment gets visible.
onResume() : Fragment becomes active.
onPause() : The system calls this method as the first
indication that the user is leaving the fragment. This
is usually where you should commit any changes that
should be persisted beyond the current user session.
onStop() : Fragment going to be stopped by calling
onStop()
onDestroyView() : Fragment view will destroy after
call this method
onDestroy() :called to do final clean up of the
fragment’s state but Not guaranteed to be called by
the Android platform.

Q15. Data Storage in Android.


Ans: Data storage is a critical aspect of Android
application development. Android provides developers
with several options for storing data, including:
Shared Preferences: Shared Preferences are a
simple key-value storage mechanism that allows
developers to store small amounts of data, such as
user preferences, settings, or other configuration
data.
Internal Storage: Internal storage is a private file
system that is only accessible to the application that
created it. Internal storage can be used to store
application-specific data, such as cached images,
downloaded files, or user data.
External Storage: External storage is a public file
system that can be accessed by any application.
External storage can be used to store large files,
such as media files or documents, that need to be
shared between applications or persisted across app
updates.
SQLite Database: SQLite is a powerful relational
database management system that is integrated into
the Android platform. SQLite can be used to store
large amounts of structured data, such as user data
or application settings.
Content Providers: Content Providers are a powerful
data storage mechanism that allows applications to
share data with other applications. Content Providers
can be used to store and retrieve data in a
centralized location, such as a SQLite database.
Cloud Storage: Cloud storage services, such as
Google Drive or Amazon S3, can be used to store and
synchronize data across devices and platforms.

The choice of data storage mechanism depends on


the type and amount of data to be stored, as well as
the specific needs of the application. By choosing the
appropriate data storage mechanism, developers can
ensure that their applications are efficient, secure,
and scalable.
Refer PPT ‘kotlin2’ for detailed answers
Q16. Gallery View in Android.
Ans: In Android, Gallery is a view that can show items
in a center-locked, horizontal scrolling list, and hence
the user can able to select a view, and then the user-
selected view will be shown in the center of the
Horizontal list. “N” number of items can be added by
using the Adapter. The adapter is a bridging
component between the UI component and the data
source.
Steps for creating Gallery View :
1. Setting up the Project:
We start by creating a new Android project in
either Java or Kotlin.
2. Designing the User Interface:
We design the user interface with a horizontal
Gallery and an Image View to display the selected
item. The Gallery is where the user can swipe
through items, and the ImageView is where the
selected item will be shown.
3. Using an Adapter:
We use something called an Adapter. Think of it
like a messenger between the actual data (the
items we want to display) and the user interface
components (like the Gallery).
The Adapter is responsible for taking out data and
making it ready for the Gallery to display.
4. Adding Items to the Gallery:
We create an array or a list items (could be image,
text, etc). This data is what the Adapter will use
to fill the Gallery.
In Android, this could be images or any other
content you want to display.
Example :
Refer ‘kotlin 2’ ppt pg no. 63 to 68

Q17. Process and Thread in Android.


Ans: Process: Processes are basically the programs
that are dispatched from the ready state and are
scheduled in the CPU for execution. PCB(Process
Control Block) holds the concept of process. A
process can create other processes which are known
as Child Processes. The process takes more time to
terminate and it is isolated means it does not share
the memory with any other process.
Android’s ‘ActivityManager’ is responsible for
managing processes, starting and stopping them as
needed based on system resource constraints and
user interaction.
Thread: Thread is the segment of a process which
means a process can have multiple threads and these
multiple threads are contained within a process. A
thread has three states: Running, Ready, and
Blocked.
The thread takes less time to terminate as compared
to the process but unlike the process, threads do not
isolate.
Android provides several threading mechanisms,
including the ‘Thread’ class, ‘Runnable’ interface,
‘AsyncTask’, ‘HandlerThread’, and various executor
services.
Difference between Process and Thread:

S.NO Process Thread

Process means any program is in


Thread means a segment of a process.
1. execution.

The process takes more time to


The thread takes less time to terminate.
2. terminate.
S.NO Process Thread

3. It takes more time for creation. It takes less time for creation.

It also takes more time for context


It takes less time for context switching.
4. switching.

The process is less efficient in terms Thread is more efficient in terms of


5. of communication. communication.

We don’t need multi programs in action


Multiprogramming holds the concepts
for multiple threads because a single
of multi-process.
6. process consists of multiple threads.

7. The process is isolated. Threads share memory.

A Thread is lightweight as each thread in


The process is called the heavyweight
a process shares code, data, and
process.
8. resources.

Thread switching does not require


Process switching uses an interface in
calling an operating system and causes
an operating system.
9. an interrupt to the kernel.

If one process is blocked then it will


If a user-level thread is blocked, then all
not affect the execution of other
other user-level threads are blocked.
10. processes

The process has its own Process Thread has Parents’ PCB, its own
Control Block, Stack, and Address Thread Control Block, and Stack and
11. Space. common Address space.

Since all threads of the same process


share address space and other resources
Changes to the parent process do not
so any changes to the main thread may
affect child processes.
affect the behavior of the other threads
12. of the process.

No system call is involved, it is created


A system call is involved in it.
13. using APIs.
S.NO Process Thread

The process does not share data with


Threads share data with each other.
14. each other.

Q18. ListView in Android.


Ans: Android ListView is a ViewGroup that is used to
display the list of items in multiple rows and contains
an adapter that automatically inserts the items into
the list. The main purpose of the adapter is to fetch
data from an array or database and insert each item
that placed into the list for the desired result. So, it
is the main source to pull data from strings.xml file
which contains all the required strings in Java or
XML files.
In Android, a ‘ListView’ is a UI component that
displays a scrollable list of items.
Example:
The overall purpose of this ListView is to act as a
container for displaying a list of items. To make it
functional, you would typically need to create an
adapter to provide data for the ListView. The
adapter is responsible for mapping the data to the
individual views within the ListView.
Additionally, you may define the layout for each item
in the list using a separate XML layout file.
Q20. Audio Manager Class in Android.
Ans: AudioManager is a class provided by Android
which can be used to control the ringer volume of
your Android device. With the help of this Audio
Manager class, you can easily control the ringer
volume of your device. Audio Manager Class can be
used by calling the getSystemService() method in
Android. When you create Audio Manager Class then
you can use setRingerMode() method to change the
ringer volume of your device. The setRingerMode()
method takes an integer parameter to set the ringer
profile of your device. There are three different
integer parameters that need to be passed in
setRingerMode() method are as follows:

Example:
Refer ‘kotlin 2’ ppt pg no. 218 to 223

Q21. Media Player Class in Android.


Ans: MediaPlayer Class in Android is used to play
media files. Those are Audio and Video files. It can
also be used to play audio or video streams over the
network. So in this article, the things discussed are:
 MediaPlayer State diagram
 Creating a simple audio player using MediaPlayer
API. Have a look at the following image. Note
that we are going to implement this project using
the Kotlin language.
In the above MediaPlayer state diagram, the oval
shape represents the state of the MediaPlayer
instance resides in.
Example:
Refer ‘kotlin 2’ ppt pg no. 210 to 214

Q22. Zoom Applications in Android.


Ans: In Android, Zoom Control is a class that has
some set of methods that are used to control the
zoom functionality. It has two buttons that are used
to control the zoom functionality (ie Zoom In and
Zoom Out). Zoom Control Class has been deprecated
in API Version 29. The functionalities offered by
ZoomControls class are handled in a better way
through Custom view and custom layouts then
dedicated zoom controls widgets.
Important Methods of Zoom Controls:
 Let say ZoomControls be the reference of
ZoomControl class which is being used to call the
different method of ZoomControls class.
ZoomControl zoomControls = (ZoomControls)
findViewById(R.id.simpleZoomControl);
 show(): This method is used to show the zoom
controls on the App UI.
// will show the zoom controls
zoomControls.show()
 hide(): This method is used to hide the zoom
controls on the App UI.
// will hide the zoom controls
zoomControls.hide()
 setOnZoomInClickListener(OnClickListenerlisten
er): This method is invoked when Zoom In button
is pressed. It is used to customize the UI that
will be shown when the zoom-in button is being
pressed.
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// add the code which will be executed when
// the zoom in button has been pressed
}
});

 setOnZoomOutClickListener(OnClickListenerlist
ener): This method is invoked when Zoom Out is
pressed. It too works in the same manner as the
setOnZoomInClickListener() method works, but
it minimizes ie converges the UI.
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// add the code which will be executed when
// the zoom out button has been pressed
}
});

 setIsZoomInEnabled(boolean isEnabled): It is
one of the methods of Zoom Controls which is
used to enable or disable the zoom-in
functionality.
// it will enable the zoomIn button
zoomControls.setIsZoomInEnabled(true)
// it will disable the zoomIn button
zoomControls.setIsZoomInEnabled(false)
 setIsZoomOutEnabled(boolean isEnabled): It is
also one of the methods of Zoom Controls, which
is used to enable or disable the zoom out
functionality.
// it will enable the zoomOut button
zoomControls.setIsZoomOutEnabled(true)
// it will disable the zoomOut button
zoomControls.setIsZoomOutEnabled(false)
 setZoomSpeed(long speed): This is used to set
the zoom speed of the zoom that is being done
with zoom controls.
Important Attributes of Zoom Controls:
 id: This attribute is used to give the zoom
controls a unique identity.
<ZoomControls android:id=”@+id/zoom_controls/>
 background: This is used to give the background
color to the zoom controls.
<ZoomControls
android:id=”@+id/zoom_controls
android:background=”#fffff”/>
 padding: This is used to give padding on the sides
of zoom controls.
<ZoomControls
android:id=”@+id/zoom_controls
android:padding=”20dp”/>

Q23. ImageSwitcher in Android.


Ans: Android ImageSwitcher is a user interface
widget that provides a smooth transition animation
effect to the images while switching between them
to display in the view.
ImageSwitcher is subclass of View Switcher which is
used to animate one image and display next one.
Generally, we use ImageSwitcher in two ways
mutually in XML layout and programmatically in Kotlin
file.
We should define an XML component to use
ImageSwitcher in our android application.
ImageSwitcher is a widget in Android that is used to
switch between images with a smooth transition. It
can be useful in applications where you want to
display a sequence of images and provide a smooth
transition effect when switching between them.
Example:
Refer ‘kotlin 2’ ppt pg no. 20 to 25

Q24. JobScheduler in Android.


Ans:
Q25. Intent in Android.
Ans: In Android, it is quite usual for users to witness
a jump from one application to another as a part of
the whole process, for example, searching for a
location on the browser and witnessing a direct jump
into Google Maps or receiving payment links in
Messages Application (SMS) and on clicking jumping
to PayPal or GPay (Google Pay). This process of taking
users from one application to another is achieved by
passing the Intent to the system. Intents, in general,
are used for navigating among various activities
within the same application, but note, is not limited
to one single application, i.e., they can be utilized
from moving from one application to another as well.
Some Important Method of Intent and their
Description:

Methods Description

This is to launch a new activity or get an existing


Context.startActivity()
activity to be action.

This is to start a new service or deliver instructions for


Context.startService()
an existing service.

Context.sendBroadcast() This is to deliver the message to broadcast receivers.

Types of Android Intents:


There are two types of intents in android as follows-
 Implicit Intent: Implicit Intent doesn’t specify
the component. In such a case, intent provides
information on available components provided by
the system that is to be invoked. For example,
you may write the following code to view the
webpage.
Syntax:
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.google.com"));
startActivity(intent);
 Explicit Intent: Explicit Intent specifies the
component. In such a case, intent provides the
external class to be invoked.
Syntax:
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);

Q26. Widget in Android.


Ans: A widget is a small gadget or control of your
android application placed on the home screen.
Widgets can be very handy as they allow you to put
your favourite applications on your home screen in
order to quickly access them. You have probably seen
some common widgets, such as music widget, weather
widget, clock widget etc.
A widget is small, interactive component that resides
on the user’s home screen or lock screen.
It provides a quick glance or direct interaction with
certain functionalities of an app without opening the
full application.
Types of Widgets:
There are different types of widgets, including app
widgets and home screen shortcuts.
App widgets can display information or provide
functionality on the home screen.
Implementation:
Developers can create app widgets using the App
Widget framework in Android.
Widgets are implemented using a combination of XML
layout files and a special ‘AppWidgetProvider’ class.
Updating Control:
Widgets can periodically update their content to
display relevant information.
Updates can be triggered by the system or by the
app itself.
User Interaction:
Widgets often support user interaction, allowing
users to perform certain actions without opening the
full app.
Examples include tapping a widget to open a specific
screen on initiating a refresh.

Q28. Versioning in Android.


Ans:
Q29. Publishing/Deploy the Application.
Ans:
Q30. AsyncTask.
Ans:
Q32. Visibility Modifiers in Kotlin.
Ans:
Q33. Menu in Android.
Ans: Refer ‘kotlin 2’ ppt from pg no. 337 to 360

Q34. Firebase RealTime Database.


Ans:
Q35. Building Blocks of Android.
Ans: There are some necessary building blocks that an
Android application consists of. These loosely coupled
components are bound by the application manifest
file which contains the description of each
component and how they interact. The manifest file
also contains the app’s metadata, its hardware
configuration, and platform requirements, external
libraries, and required permissions. The four main
building blocks of Android are as follows:
1. Activities:
Activities are said to be the presentation layer of
our applications. The UI of our application is built
around one or more extensions of the Activity class.
By using Fragments and Views, activities set the
layout and display the output and also respond to the
user’s actions. An activity is implemented as a
subclass of class Activity.
2. Services:
Services are like invisible workers of our app. These
components run at the backend, updating your data
sources and Activities, triggering Notification, and
also broadcast Intents. They also perform some
tasks when applications are not active. A service can
be used as a subclass of class Service.
3. Content Providers:
It is used to manage and persist the application data
also typically interacts with the SQL database. They
are also responsible for sharing the data beyond the
application boundaries. The Content Providers of a
particular application can be configured to allow
access from other applications, and the Content
Providers exposed by other applications can also be
configured.
A content provider should be a sub-class of the class
ContentProvider.
4. Broadcast Receivers:
They are known to be intent listeners as they enable
your application to listen to the Intents that satisfy
the matching criteria specified by us. Broadcast
Receivers make our application react to any received
Intent thereby making them perfect for creating
event-driven applications.

Q36. Event Handling.


Ans:
Q37. Drag Functionality.
Ans:
Q38. Spinner.
Ans:
Q39. Animation in Android.
Ans:
Q41. Features of SQLite Databases.
Ans: Features of SQLite Database are as follows:
 The transactions follow ACID properties i.e.
atomicity, consistency, isolation, and durability
even after system crashes and power failures.
 The configuration process is very easy, no setup
or administration is needed.
 All the features of SQL are implemented in it
with some additional features like partial
indexes, indexes on expressions, JSON, and
common table expressions.
 Sometimes it is faster than the direct file
system I/O.
 It supports terabyte-sized databases and
gigabyte-sized strings and blobs.
 Almost all OS supports SQLite like Android,
BSD, iOS, Linux, Mac, Solaris, VxWorks, and
Windows (Win32, WinCE, etc. It is very much
easy to port to other systems.
 A complete database can be stored in a single
cross-platform disk file.

Q42. Drawable Class.


Ans:
Q43. Android Gestures and Method.
Ans:

Q44. AutoCompleteTextView.
Ans:

You might also like