Question Bank
Question Bank
August, 2005
- Google acquired android Incorporation.
- Rumors a g1 Phone is about to come out.
2007
- Google Announced to introduce Open source O.S.
- Also created Open Handset Aliance.
2008
- The public version Android SDK 1.0 is released.
- World first Android Phone G1 phone manufactured bt HTC.
2009
- New version of the operating system are released: Cupcake(1.5),
Donut(1.6) and Éclair(2.0 and 2.1).
2010
- Android is second only to BlueBerry as the best selling smart
phone platform.
2011
- Android is the #1 mobile platform by number of new activations
and number of devices sold.
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.
Application framework
Application 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
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.
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.
Cupcake 1.5
Donut 1.6
SDK tools: SDK tools are generally platform independent and are required no
matter which android platform you are working on. When you install the
Android SDK into your system, these tools get automatically installed.
Platform tools: The platform tools are customized to support the features of the
latest android platform. The platform tools are typically updated every time you
install a new SDK platform. Each update of the platform tools is backward
compatible with older platforms.
ii. JDK
JDK is an acronym for Java Development Kit. The Java Development Kit
(JDK) is a software development environment which is used to develop
java applications and applets. It physically exists. It contains JRE +
development tools. The JDK contains a private Java Virtual Machine (JVM)
and a few other resources such as an interpreter/loader (Java), a
compiler (javac), an archiver (jar), a documentation generator (Javadoc)
etc. to complete the development of a Java Application.
Disadvantages
DVM supports only Android Operating System.
For DVM very few Re-Tools are available.
Requires more instructions than register machines to implement the
same high-level code.
App Installation takes more time due to dex.
More internal storage is required.
AndroidManifest.xml:
Every project in android includes a manifest file, which is
AndroidManifest.xml, stored in the roor directory of its project hierarchy.
This file includes nodes for each of the Activities, Services, Content
Providers and Broadcast Receiver that make the application and using
Intent Filters and Permissions, determines how they co-ordinate with each
other and other applications
Java:
The Java folder contains the Java source code files. These files are used
as a controller for controlled UI (Layout file). It gets the data from the
Layout file and after processing that data output will be shown in the UI
layout. It works on the backend of an Android application.
Res:
The 'res' stands for Resource file. It can store resource files such as pictures,
XML files, etc. It contains some additional folders such as Drawable,
Layout and Values.
Drawable:
A drawable folder contains resource type file (something that can be
drawn). Drawable may take a variety of file Bitmap (PNG, JPEG), Nine
Patch, Vector (XML), Shape, Layers, States, Levels and Scale.
Mipmap:
Mipmap folder contains the image Asset file can be used in Android
studio application. You can generate the following icon types like
Launcher icons, Action bar and tab icons, and Notification icons.
Colors.xml:
colors.xml file contains color resources of the android application.
Different color values are indentified by a u nique name that can be in
the android application program.
Build.gradle(Module: app):
This defines that module-specific build configuration. Here you can add
dependancies what you need in your android application.
Q.13. Explain UI components
Ans: UI (User Interface) components are the building blocks of any Android
application's interface. They are responsible for creating the interactive user
interface that the user can interact with. The Android platform provides a variety
of UI components that developers can use to create the desired interface for
their applications. Here are some of the most common UI components used in
Android:
1. TextView: A TextView is a UI component used to display text on the screen.
It can display either a single line of text or multiple lines of text.
Syntax : :- <Linear Layout xmls:android=
"http://schemas.android.com/apk/res/android"
<TextView
//attributes to describe it
/>
</LinearLayout>
<ImageButton
//other attributes...
android:src= “@drawable/add_icon”/>
</LinearLayout>
6.ImageView: An ImageView is a UI component used to display images on
the screen. It can be used to display images from a local file or from the
internet.
9. RadioGroup : It’s a group of Radio buttons that are alike. In this, only one of
all the buttons can be chosen.
Syntax :- <Linear Layout
xmls:android= ”http://schemas.android.com/apk/res/android”>
<RadioGroup android:orientation="vertical">
<RadioButton android:text="Radio Button 1"/>
<RadioButton android:text="Radio Button 2"/>
<RadioButton android:text="Radio Button 3"/>
</RadioGroup>
</LinearLayout>
10. Spinner: A Spinner is a UI component used to display a drop-down list of
options. It can be used to create a list of options where the user can select
one option.
11. ProgressBar: In Android, we have a progress bar that shows the progress of
some action that is happening like pasting a file to some location. A
progress bar can be in two modes:
Determinate Mode:
In this, the progress is shown with the percent of action completed.
Also, the time to be taken is already determined.
Indeterminate Mode:
In this, there is no idea of when the task would be completed,
therefore, it functions continuously.
It gives a virtual Clock/watch to select it. This virtual clock makes it easy to
choose the time.
This enables the user to choose a particular date using either a calendar or a
dropdown. These both are made to make it easier for the user to pick up a date
and a time.
14. AutoCompleteTextView:- AutoCompleteTextView is an extension of EditText.
In this UI element, the user is provided with a few suggestions of some
values/texts. The value can be chosen by the user while filling
AutoCompleteTextView.
- Linear Layout
- Relative Layout
- Table Layout
- Absolute Layout
- Frame Layout
Attributes :
android:id
android:baselineAligned
android:gravity
android:orientation
android:divider
android:layout_width
Example :-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
</LinearLayout>
android:id
android:layout_x
android:layout_y
android:layout_width
android:layout_height
Example :-
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_x="50dp"
android:layout_y="50dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:layout_x="150dp"
android:layout_y="150dp" />
</AbsoluteLayout>
Attributes :-
android:layout_width
android:layout_height
android:id
android:gravity
android:ignoreGravity
Example :-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me!"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Attributes :-
android:layout_width
android:layout_height
android:id
android:foreground
Example :-
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background_image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
android:layout_gravity="center" />
</FrameLayout>
Attributes :-
android:layout_width
android:layout_height
android:id
android:collapseColumns
android:shrinkColumns
Examples :-
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:textStyle="bold"
android:padding="5dp" />
<TextView
android:text="Description"
android:textStyle="bold"
android:padding="5dp" />
<TextView
android:text="Price"
android:textStyle="bold"
android:padding="5dp" />
</TableRow>
<TableRow>
<TextView
android:text="Item 1"
android:padding="5dp" />
<TextView
android:text="Description of item 1"
android:padding="5dp" />
<TextView
android:text="$10"
android:padding="5dp" />
</TableRow>
<TableRow>
<TextView
android:text="Item 2"
android:padding="5dp" />
<TextView
android:text="Description of item 2"
android:padding="5dp" />
<TextView
android:text="$15"
android:padding="5dp" />
</TableRow>
</TableLayout>
Attributes of ProgressBar:
android:id: Specifies a unique ID for the ProgressBar.
android:layout_width: Specifies the width of the ProgressBar.
android:layout_height: Specifies the height of the ProgressBar.
android:max: Specifies the maximum value for the ProgressBar.
android:progress: Specifies the initial progress value for the ProgressBar.
android:secondaryProgress: Specifies the secondary progress value for the
ProgressBar.
android:indeterminate: Specifies whether the ProgressBar is in the indeterminate
state or not.
android:visibility: Specifies whether the ProgressBar is initially visible or invisible.
android:style: Specifies the style of the ProgressBar.
24. Explain RadioButton and RadioGroup with example
Ans:
RadioButton and RadioGroup are UI components in Android that are used to
provide users with a set of mutually exclusive options to choose from.
RadioButton is a button that represents a single choice among a set of
options. It can be selected or unselected by the user, and only one
RadioButton can be selected at a time.
RadioGroup is a container that holds multiple RadioButtons and ensures that
only one RadioButton in the group is selected at a time. When a RadioButton
is selected, the previously selected RadioButton in the same group is
automatically deselected.
Here's an example of how to use RadioButton and RadioGroup in Android:
1. In the XML file, define a RadioGroup and multiple RadioButton elements
inside it, each with a unique ID and a text label:
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radio_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<RadioButton
android:id="@+id/radio_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
<RadioButton
android:id="@+id/radio_button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3" />
</RadioGroup>
2. In the Java code, get a reference to the RadioGroup and set an
OnCheckedChangeListener to handle changes in the selection:
RadioGroup radioGroup = findViewById(R.id.radio_group);
radioGroup.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// Do something when a RadioButton in the group is selected
RadioButton radioButton = findViewById(checkedId);
String selectedOption = radioButton.getText().toString();
Toast.makeText(MainActivity.this, "Selected option: " + selectedOption,
Toast.LENGTH_SHORT).show();
}
});
27. List different adapters used in UI design of GridView and ListView controls
Ans:
In Android, adapters are used to bind data to UI components such as GridView
and ListView controls. Here are the different types of adapters used in the UI
design of GridView and ListView controls:
- ArrayAdapter: This adapter is used to bind an array of data to a UI
component such as a ListView or Spinner.
- SimpleAdapter: This adapter is used to bind data in the form of a list of
Maps to a UI component such as a ListView.
- BaseAdapter: This is a more flexible adapter that allows us to create
custom adapters to bind data to a UI component such as a ListView or
GridView.
- CursorAdapter: This adapter is used to bind data from a database query
to a UI component such as a ListView.
- RecyclerView.Adapter: This adapter is used to bind data to a
RecyclerView, which is a more modern and flexible replacement for the
ListView and GridView controls.
Each of these adapters has its own strengths and weaknesses, and the choice
of which one to use depends on the specific needs of the application.
10. android:minDate: This attribute sets the minimum selectable date in the
DatePicker.
11. android:maxDate: This attribute sets the maximum selectable date in the
DatePicker.
12. android:startYear: This attribute sets the start year for the DatePicker calendar.
13. android:endYear: This attribute sets the end year for the DatePicker calendar.
we can also add additional information to the Intent using various methods,
such as:
- intent.putExtra(key, value);
This method is used to add extra data to the intent, where key is a string that
identifies the data and value is the actual data you want to include.
- intent.setAction(action);
This method is used to set the action of the intent, which defines the type of
operation that the intent is intended to perform.
- intent.setData(uri);
This method is used to set the data URI of the intent, which specifies the data
that the intent is intended to operate on.
Overall, the Intent syntax in Android provides a flexible and powerful way to
initiate actions and communicate between different components within an app
or between different apps.
As shown in the diagram, there are several stages in the activity life cycle, which
are:
Created - When an activity is first created, the onCreate() method is called. In
this stage, the activity is initialized and its user interface is created.
Started - After the onCreate() method has been called, the onStart() method is
called. At this stage, the activity becomes visible to the user, but it is not yet in
the foreground.
Resumed - When the activity is brought to the foreground and becomes the
focus of user interaction, the onResume() method is called. This is the stage
where the activity is active and the user can interact with it.
Paused - If another activity is launched on top of the current activity, the
onPause() method is called. In this stage, the activity is still visible to the user, but
it has lost focus and cannot interact with the user.
Stopped - If the activity is no longer visible to the user, the onStop() method is
called. This can happen if the activity is finished or if another activity has taken
over the screen.
Destroyed - When the activity is finished or if the system needs to free up
memory, the onDestroy() method is called. This is the stage where the activity is
completely removed from memory and its resources are released.
36] What is Fragment (or sub-activity) life cycle and its methods?
Ans: The Fragment lifecycle is similar to that of an activity, with some additional
methods that are specific to fragments. Understanding the
Fragment lifecycle is essential for developing robust and
responsive Android applications that use fragments.
Here is a diagram that illustrates the Fragment lifecycle in Android:
As shown in the diagram, there are several stages in the Fragment
lifecycle, which are:
onAttach() - When a fragment is attached to an activity, the
onAttach() method is called. This is where the fragment is
associated with its parent activity, and you can get a reference
to the activity using the getActivity() method.
onCreate() - After the fragment is attached to the activity, the
onCreate() method is called. This is where you can initialize
the fragment, such as setting up UI components and other
resources.
onCreateView() - After the onCreate() method is called, the
onCreateView() method is called. This is where you can inflate
the fragment's layout and set up its user interface.
onActivityCreated() - After the fragment's view hierarchy is
created, the onActivityCreated() method is called. This is where
you can access the parent activity's view hierarchy and set up
any necessary communication between the activity and the
fragment.
onStart() - When the parent activity starts, the onStart() method is
called for the attached fragments. This is where you can start any background
threads or services that the fragment needs.
onResume() - When the parent activity resumes, the onResume() method is
called for the attached fragments. This is where the fragment becomes active
and can interact with the user.
onPause() - If another activity comes to the foreground or the parent activity is
paused, the onPause() method is called for the attached fragments. This is
where the fragment must save its state or stop any background threads or
services.
onStop() - When the parent activity is stopped, the onStop() method is called for
the attached fragments. This is where you should clean up any resources used
by the fragment.
onDestroyView() - When the fragment's view hierarchy is destroyed, the
onDestroyView() method is called. This is where you should release any resources
used by the fragment's UI components.
onDestroy() - After the view hierarchy is destroyed, the onDestroy() method is
called. This is where you should release any resources used by the fragment.
onDetach() - When the fragment is detached from its parent activity, the
onDetach() method is called. This is where the fragment is disassociated from its
parent activity.
38] List the different methods of callback methods of Service base class.
Ans.
In Android, the Service class provides several callback methods that allow
developers to manage the life cycle and interactions of the service. Some of
the common callback methods of the Service class are:
onCreate(): This method is called when the service is first created. It is used to
perform any one-time initialization needed for the service.
onStartCommand(): This method is called when the service is started using
startService() method. It is used to handle the intent sent to the service and
perform the desired operation.
onBind(): This method is called when a client binds to the service using
bindService() method. It returns an IBinder object that the client can use to
communicate with the service.
onUnbind(): This method is called when all clients have disconnected from the
service using unbindService() method.
onDestroy(): This method is called when the service is being destroyed. It is used
to release any resources used by the service.
onTaskRemoved(): This method is called when a task that the service is running is
removed from the recent apps list.
These methods provide a way for developers to manage the lifecycle and
interactions of the service and ensure that it performs as expected.