0% found this document useful (0 votes)
83 views22 pages

Android App Development - Questions Answer - Habib

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views22 pages

Android App Development - Questions Answer - Habib

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Android App Development

Short Questions :
1. List five android version along with the name.
 Android 12 (Snow Cone)
 Android 11 (Red Velvet Cake)
 Android 10 (Q)
 Android 9.0 (Pie)
 Android 8.0 (Oreo)
2. What are different types of Layouts available in Android Studio?
 LinearLayout
 RelativeLayout
 ConstraintLayout
 TableLayout
 FrameLayout
 GridLayout
3. Describe an activity and its parts.
An activity is a single screen in an Android app that contains a user interface. The different
parts of an activity include:
onCreate() method: This is where the activity is initialized and the layout is set.
onStart() method: This is called when the activity becomes visible to the user.
onResume() method: This is called when the activity is in the foreground and the user is
interacting with it.
onPause() method: This is called when the activity is no longer in the foreground but still
visible to the user.
onStop() method: This is called when the activity is no longer visible to the user.
onDestroy() method: This is called when the activity is about to be destroyed.
4. How to connect an adapter with List View? Write down the codes for it.
Here is an example of connecting an adapter with List View:

ListView listView = findViewById(R.id.listview);


String[] items = {"Item 1", "Item 2", "Item 3"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
listView.setAdapter(adapter);

5. Which software is used to develop Android Programming ? What are its dependencies ?
Android Studio is the official software used to develop Android Programming. Its
dependencies include the Android SDK, Gradle, and the Java Development Kit (JDK).
6. What is Android ?
Android is a mobile operating system based on the Linux kernel and developed by Google. It
is designed primarily for touch screen mobile devices such as smartphones and tablets.
7. Android is Developed by ?
Android was developed by the Open Handset Alliance, led by Google, and other
companies.
8. In which directory XML layouts files are stored?
XML layouts files are stored in the "res/layout" directory.
9. Which programming language is used for android application development?
Java and Kotlin are the two main programming languages used for Android application
development.
10. What is manifest.xml in android?
The manifest.xml file in Android is a required file that contains essential information about
the app, such as its package name, permissions, activities, and services.
11. Which is the OS used as the kernel in Android ?
The Linux kernel is used as the OS kernel in Android.
12. In which file of an android project do you define the various permission required by an
Android App ?
The various permissions required by an Android app are defined in the AndroidManifest.xml
file.
13. Give an example of a Runtime (or Dangerous ) Permission on android.
An example of a Runtime (or Dangerous) Permission on Android is the
"READ_CONTACTS" permission, which allows the app to access the user's contacts.
14. What is the Toast() method used for in an Android App ?
The Toast() method in an Android app is used to display a short message to the user that
appears as a small pop-up on the screen.
15. How do you define the Main Activity in an Android App ?
The Main Activity in an Android app is defined in the AndroidManifest.xml file using the
"android.intent.action.MAIN" and "android.intent.category.LAUNCHER" intent filters.
16. What is meant by a layout in Android application ? Layouts are defined in which file
generally.
It is used to define the user interface and the position of UI elements on the screen. It is
defined in an XML file.
17. What do you understand by an intent in Android Application?
It is an object used to interact with other components and pass data between them.
18. State the difference between TextView and EditText.
TextView is used to display text, while EditText allows the user to input and edit text.
19. What do you understand about BroadcastReceiver ?
It is a component used to receive and handle broadcast messages sent by the system or other
apps.
20. What do you know about ContentProvider ?
It is a component used to manage access to a structured set of data and provides a
standardized interface for other apps to query, insert, update, and delete data.
Long Questions :
1. What is the general architecture of Android App ? What are the different stacks in it ?
Please Discuss.
The general architecture of an Android app is based on a layered approach, with each layer
having its own distinct functionality. The architecture follows the Model-View-Controller
(MVC) pattern and is composed of the following stacks:

a) Linux Kernel Stack: The bottom layer of the Android architecture is the Linux kernel. It
provides a core set of services to the upper layers of the Android architecture, including
device drivers, memory management, process management, and network stack.
b) Native Libraries Stack: Above the Linux kernel is the native libraries stack, which
includes the libraries written in C or C++ that are used by the Android system. These
libraries provide access to hardware components, such as camera, sensors, and audio.

c) Android Runtime Stack: The Android Runtime stack includes the Dalvik Virtual
Machine, which is responsible for running Android apps. It also includes the Android
core libraries, which provide the APIs used by Android apps to interact with the system.

d) Application Framework Stack: The Application Framework stack provides the building
blocks for developing Android apps. It includes a range of APIs for handling UI
elements, data storage, notifications, and connectivity. The stack also includes various
managers and services for handling activities, intents, and content providers.

e) Application Stack: The top layer of the Android architecture is the Application stack,
which includes the apps that are installed on an Android device. Each app runs in its own
process, and the Android system manages the resources and memory for each app.

In summary, the Android architecture is composed of multiple layers, each with its own
functionality. The layers are built on top of the Linux kernel and include native libraries, the
Android runtime, the application framework, and the application stack. Together, these
layers provide the building blocks for developing Android apps with a rich set of
functionalities.

2. What are the different states in Android App life cycle ? Discuss about each of the
methods in it.
The Android app lifecycle includes several states, and the Android system transitions an app
through these states based on user interaction and system events. The different states in the
Android app lifecycle are:

Not Running: This is the initial state when an app is not running. The system does not
allocate any resources for the app in this state.

Inactive (or Stopped): When an app is opened for the first time, it enters the inactive state.
In this state, the app has been launched but is not yet visible to the user. The system may
remove the app from memory to free up resources.

Active (or Running): When the app becomes visible on the screen, it enters the active state.
In this state, the app is running and is interacting with the user.
Paused: When an app loses focus or is partially obscured by another app, it enters the
paused state. In this state, the app is still running but is not visible to the user. The system
may kill the app to free up resources.

Stopped: When an app is no longer visible or has been closed, it enters the stopped state. In
this state, the app is no longer running, and the system may reclaim its resources.

Each state in the Android app lifecycle is associated with a set of methods, which are called
by the system during the app lifecycle. These methods allow developers to manage the app's
resources and state in each state. Here are the different methods associated with each state:

Not Running: No methods are called in this state.

Inactive (or Stopped):

onCreate(): This method is called when the app is launched for the first time.
onStart(): This method is called when the app is about to become visible to the user.
Active (or Running):
onResume(): This method is called when the app is visible to the user and is running in the
foreground.
onPause(): This method is called when the app loses focus or is partially obscured by another
app.
Paused:
onPause(): This method is called when the app loses focus or is partially obscured by another
app.
onStop(): This method is called when the app is no longer visible to the user.
Stopped:
onRestart(): This method is called when the app is about to be restarted.
onStart(): This method is called when the app is about to become visible to the user.
onDestroy(): This method is called when the app is about to be terminated.
In summary, understanding the different states and methods associated with the Android app
lifecycle is important for developing high-quality apps. Developers can use these methods to
manage the app's resources and state in each state, ensuring a smooth user experience.

3. What are the different data passing mechanism used in Android App ? Discuss each of
the procedures.
Data passing between components is an essential part of any Android app. There are several
methods to pass data between components, including:

a) Intent: Intents are used to communicate between activities, services, and broadcast
receivers. An Intent is an object that provides a channel of communication between two
components. The Intent carries data between components through a key-value pair. There
are two types of Intent - Explicit Intent and Implicit Intent.

b) Bundle: A Bundle is an object that holds a set of key-value pairs. It is used to pass data
between activities. Bundle is usually used when data needs to be passed between
activities that are within the same application.

c) Shared Preferences: Shared Preferences is a way of storing data in key-value pairs that
are stored in an XML file on the device. It is used to store small amounts of data, such as
user preferences, user settings, and application state.

d) Content Providers: Content providers are used to manage shared data sets. They allow
one application to access data from another application. A content provider is a way to
share data between applications, and it is typically used when data needs to be shared
between multiple applications.

e) Parcelable: Parcelable is a way of passing data between activities. It is used to send


custom objects between activities. Parcelable is used to serialize objects and send them
as a bundle between activities.
Each of these data passing mechanisms has its own advantages and disadvantages.
Developers should choose the appropriate method based on the requirements of the
application.

4. What are the different ways of implementing Broadcast Receiver ? Write down each of
these using examples in codes.
A BroadcastReceiver is an Android component that listens for system-wide broadcast
announcements. There are two ways to implement a BroadcastReceiver in an Android app:
A) Static Registration: In this method, the BroadcastReceiver is registered in the
AndroidManifest.xml file with a specific intent filter. This means that the BroadcastReceiver
will receive broadcasts that match the intent filter, even when the app is not running. Here is
an example of static registration:
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>

The above code registers the MyBroadcastReceiver class to receive three different
broadcasts - BOOT_COMPLETED, ACTION_POWER_CONNECTED, and
ACTION_POWER_DISCONNECTED.
B) Dynamic Registration: In this method, the BroadcastReceiver is registered
programmatically in the app code. This method allows for more flexibility as the app can
register and unregister the BroadcastReceiver as required. Here is an example of dynamic
registration:
public class MyActivity extends Activity {
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Do something when the broadcast is received
}
};

@Override
public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(myReceiver, filter);
}

@Override
public void onPause() {
super.onPause();
unregisterReceiver(myReceiver);
}
}

The above code registers a BroadcastReceiver to receive the


ACTION_BATTERY_CHANGED broadcast when the activity is resumed and unregisters it
when the activity is paused.
In summary, there are two ways to implement a BroadcastReceiver in an Android app - static
registration and dynamic registration. Developers can choose the appropriate method based
on the requirements of the app.

5. What is Retrofit ? Write down the steps to implement Retrofit with code examples.
Retrofit is a type-safe HTTP client library for Android and Java that simplifies consuming
RESTful web services. It offers an easy-to-use API, allowing developers to send network
requests with fewer lines of code and less boilerplate.
Here are the steps to implement Retrofit in an Android app:
1. Add the Retrofit dependency to your project. You can add it to your build.gradle file:

2.Create a Retrofit object with the base URL of your API. This can be done using the
Retrofit.Builder class:

3.Define an interface that describes the API endpoints. This interface should include
methods that correspond to the HTTP methods used to access the API, along with any
required parameters and return types. For example:

4. Create an instance of the interface using the Retrofit object created in step 2:

5. Use the instance of the interface to make network requests. Retrofit provides a Call object
to represent each request, which can be executed synchronously or asynchronously. For example:

In the above example, a request is made to the API to get the user with an ID of 1. The
onResponse() method is called if the request is successful, and the onFailure() method is
called if there is an error.
Overall, Retrofit simplifies the process of consuming RESTful web services in Android
apps, allowing developers to focus on the business logic of their applications.

6. Basic Overview of an Android App.


An Android app is a software application designed to run on mobile devices running the
Android operating system. It can be developed using the Android software development kit
(SDK) and the Java programming language.
The basic components of an Android app include:
a) Activities: These are the building blocks of the user interface in an Android app. Each
screen or UI in an app is an activity, and multiple activities can be combined to form a
complete app.
b) Services: These are background components that can run even if the app is not visible to
the user. Services can perform long-running operations such as downloading data or
playing music in the background.
c) Broadcast receivers: These are components that can receive and respond to system-
wide broadcast announcements, such as when the battery is low or when an incoming
call is received.
d) Content providers: These are components that manage a shared set of app data that can
be accessed by other apps.
An Android app can be developed using various software tools, including Android Studio,
Eclipse, or IntelliJ IDEA. The app can be tested using an Android emulator or a physical
Android device.
To distribute an Android app, it needs to be published on the Google Play Store or other app
stores. Before publishing, the app needs to be signed and optimized for performance.

In summary, an Android app is a software application designed to run on Android devices,


consisting of various components such as activities, services, broadcast receivers, and
content providers. It can be developed using various tools and published on app stores after
signing and optimization.

7. Discuss wrap content and fill parent android application.


In Android application development, wrap_content and fill_parent (or match_parent) are two
commonly used layout attributes for defining the width and height of UI elements.

wrap_content: When you set the width or height of a UI element to wrap_content, it will
expand or shrink to fit the content inside the element. For example, if you have a TextView
with a wrap_content width, the width of the TextView will adjust to fit the length of the text.
Similarly, if you have an ImageView with a wrap_content height, the height of the
ImageView will adjust to fit the height of the image.

fill_parent or match_parent: When you set the width or height of a UI element to


fill_parent or match_parent, the element will expand to fill the entire width or height of the
parent element. For example, if you have a LinearLayout with a vertical orientation and a
TextView with a fill_parent height, the TextView will fill the entire height of the
LinearLayout.
In Android, you can define the width and height of UI elements using various layout types
such as LinearLayout, RelativeLayout, FrameLayout, etc. You can set the width and height
attributes of the UI elements in the XML layout file or programmatically in the Java code.
It is important to use the appropriate width and height attributes based on the design
requirements of the app. Using wrap_content for elements that have long content may result
in a layout that is too large, while using fill_parent for every element may result in a
cluttered layout.

8. Explain Toast method in an android applications.


In Android application development, Toast is a mechanism for displaying short messages to
the user in a small pop-up window. Toast messages are useful for displaying information or
messages that do not require user input, such as showing a confirmation message after a
successful operation or displaying an error message if an operation failed.
The Toast class in Android provides a simple API to create and display Toast messages. The
basic syntax for creating a Toast message is as follows:

Here, context is the context of the application, text is the message to be displayed, and
duration is the length of time the message should be displayed, which can be either
Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
Once you have created a Toast message, you can display it by calling the show() method on
the Toast object.
For example, the following code creates and displays a Toast message with the text "Hello
World!" that lasts for a short duration:

Toast.makeText(getApplicationContext(), "Hello World!", Toast.LENGTH_SHORT).show();

When this code is executed, a small pop-up window appears on the screen with the message
"Hello World!" that fades away after a short period of time.
Toast messages are lightweight and easy to implement, making them a useful tool for
providing feedback to the user in an Android application.

9. Explain Android Checkbox and Android Radio Buttons Basics.


In Android, Checkbox and Radio Button are two types of widgets used for user input. Both
of these widgets provide multiple choices for the user, but they work in slightly different
ways.
A Checkbox is a widget that allows the user to select one or more options from a list of
choices. Each Checkbox is independent of the others, so the user can select or deselect each
one as they wish. Checkbox widgets are useful for allowing the user to choose multiple
options at once, such as selecting multiple items from a shopping list.
On the other hand, a Radio Button is a widget that allows the user to select only one option
from a list of choices. When the user selects one Radio Button, any other Radio Buttons in
the same group are automatically deselected. Radio Buttons are useful for presenting a list of
mutually exclusive options, such as selecting a single answer in a quiz.
To use a Checkbox or Radio Button in an Android application, you need to add the widget to
your layout file and handle the user input in your code. Here is an example of how to use a
Checkbox and a Radio Button in an Android layout:
In the code, you can handle the user input by attaching an OnCheckedChangeListener to the
Checkbox or Radio Button widget, which will be triggered whenever the user makes a
selection. Here is an example of how to handle the user input for a Checkbox and Radio
Button in Android:

CheckBox checkboxItem = findViewById(R.id.checkbox_item);


checkboxItem.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// Checkbox is selected
} else {
// Checkbox is not selected
}
}
});

RadioGroup radioGroup = findViewById(R.id.radio_group);


radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_button1:
// Option 1 selected
break;
case R.id.radio_button2:
// Option 2 selected
break;
}
}
});

In this code, the OnCheckedChangeListener is used to detect when the Checkbox or Radio
Button is checked or unchecked, and then perform some action based on the user input.
10. Discuss Android Alert Dialog.
Android AlertDialog is a pop-up dialog box that displays important information to the user
and requests their input. It can be used to display a message, ask for user input, or show a list
of options for the user to choose from.
There are two ways to create an AlertDialog in Android:
1.Using AlertDialog.Builder class: This is the preferred way of creating an AlertDialog. The
Builder class allows us to set various properties of the AlertDialog, such as its title, message,
icon, and buttons.
Example:

AlertDialog.Builder builder = new AlertDialog.Builder(this);


builder.setTitle("Title")
.setMessage("Message")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Action to be performed on click of OK button
}
})
.setNegativeButton("Cancel", null)
.show();

2.Using AlertDialog class: This method is deprecated in newer versions of Android, but can
still be used for older versions.

AlertDialog alertDialog = new AlertDialog.Builder(this).create();


alertDialog.setTitle("Title");
alertDialog.setMessage("Message");
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Action to be performed on click of OK button
}
});
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Action to be performed on click of Cancel button
}
});
alertDialog.show();

In both methods, we can customize the look and behavior of the AlertDialog to suit our
needs. AlertDialog is a powerful tool in Android development that can greatly enhance the
user experience by providing important information and options in a clear and concise
manner.
11. Android does not allow network operations on the main UI thread. Explain how does one
handle the network operations in an Android App.
Android does not allow network operations on the main UI thread because it can cause the
app to become unresponsive and even crash if the operation takes too long to complete.
Therefore, it is important to handle network operations in a separate thread or background
task to ensure that the app remains responsive.

One way to handle network operations in an Android app is by using AsyncTask. AsyncTask
is an abstract class that enables performing background operations and publishing results on
the UI thread without having to manipulate threads and/or handlers.

Here are the steps to handle network operations using AsyncTask:

1. Create a new class that extends AsyncTask.


2. Override the doInBackground() method to perform the network operation in a background
thread. This method takes a variable number of parameters and returns the result of the
computation.
3. Override the onPostExecute() method to update the UI after the background operation is
completed. This method takes the result of the doInBackground() method as its parameter.
4. Call the execute() method of the AsyncTask instance in the UI thread to start the background
operation.

Here's an example of an AsyncTask implementation for fetching data from a server:

public class FetchDataAsyncTask extends AsyncTask<String, Void, String> {

private Context context;

public FetchDataAsyncTask(Context context) {


this.context = context;
}

@Override
protected String doInBackground(String... urls) {
String result = "";
try {
URL url = new URL(urls[0]);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
while (line != null) {
line = bufferedReader.readLine();
result += line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(context, result, Toast.LENGTH_SHORT).show();
}
}

To use this AsyncTask to fetch data from a server, you can call it as follows:

new FetchDataAsyncTask(this).execute("http://example.com/data");

In this example, the doInBackground() method fetches data from the specified URL and
returns the result as a String. The onPostExecute() method updates the UI by showing a
Toast message with the result. The execute() method is called to start the AsyncTask with
the specified URL parameter.

12. What are Intents used for ? What is the difference between Implicit and Explicit Intents?

In Android, an Intent is a messaging object that is used to communicate between different


components of an app such as activities, services, and broadcast receivers. It can be used to
start an activity, start a service, or deliver a broadcast.

There are two types of Intents in Android: Implicit and Explicit.

Explicit Intents: Explicit Intents are used to start a specific component within an app, such as
a specific activity or service. An explicit Intent explicitly names the component to be started
by the Intent.

For example, the following code starts a specific activity called "MyActivity" within an app:
Intent intent = new Intent(this, MyActivity.class);
startActivity(intent);

Implicit Intents: Implicit Intents are used when the app does not know which component will
handle the Intent. An implicit Intent does not specify the component to be started, but instead
specifies the action to be performed and the data to be operated upon. The Android system
then looks for the components that can handle the Intent and displays the list of available
components to the user to choose from.

For example, the following code creates an Intent that opens the browser and navigates to a
specific URL:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.example.com"));
startActivity(intent);

In summary, Intents are used in Android to facilitate communication between different


components of an app. Explicit Intents are used when a specific component is known, while
Implicit Intents are used when the app is not aware of the specific component that will
handle the Intent.

13. What is the importance of the Android Debug Bride (ADB) in the android ecosystem ?
The Android Debug Bridge (ADB) is a command-line tool used for communication between
a computer and an Android device. It plays a significant role in the Android ecosystem,
especially during the development and debugging process.
Here are some of the important uses of ADB in the Android ecosystem:

a) Debugging: ADB allows developers to connect their Android device to a computer and
debug their apps using tools such as logcat, which shows the device's system logs.

b) Installing and uninstalling apps: Developers can use ADB to install and uninstall apps
on an Android device without having to go through the Google Play Store or other app
distribution platforms.

c) File transfer: ADB allows developers to transfer files between an Android device and a
computer.

d) Shell access: ADB provides shell access to an Android device's command-line interface,
which allows developers to execute commands directly on the device.

e) Testing: ADB can be used to test various aspects of an Android app, such as its
performance and user interface.

Overall, ADB is an essential tool for Android developers and users alike, as it provides
various functionalities that are critical for the development, debugging, and testing of
Android apps.

14. Write down the code to save file in external storage in Android Studio?
To save a file in external storage in Android Studio, the following code can be used:
// Check if external storage is available for writing
if (isExternalStorageWritable()) {
// Get the directory for the user's public pictures directory
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
"example.txt");
try {
// Create a new file output stream
FileOutputStream fos = new FileOutputStream(file);
// Write some data to the file
fos.write("Hello world!".getBytes());
// Close the output stream
fos.close();
// Show a toast message to indicate file saved successfully
Toast.makeText(getApplicationContext(), "File saved successfully", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
This code checks if the external storage is available for writing using the
isExternalStorageWritable() method. If the external storage is available, it creates a new file
with the name "example.txt" in the Downloads directory using the File class. It then writes
the string "Hello world!" to the file using a FileOutputStream and closes the output stream.
Finally, it shows a toast message to indicate that the file has been saved successfully.
15. Write down the code to save file in internal storage using Android Studio?
To save a file in internal storage using Android Studio, you can follow these steps:

Create a file object and specify the filename and directory where you want to save the file. In
this example, we will create a file called "example.txt" in the internal storage directory.

String filename = "example.txt";


File file = new File(context.getFilesDir(), filename);

Open a file output stream for the file and write data to it. In this example, we will write a
string to the file.

String data = "Hello, World!";


FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
fos.write(data.getBytes());
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}

16. What do you understand by Firebase ? What are its functionalities ? Discuss with
applications.

Firebase is a mobile and web application development platform acquired by Google in 2014.
It provides a wide range of functionalities to help developers build high-quality apps quickly
and efficiently.
Some of the key functionalities of Firebase are:

a) Realtime Database: Firebase provides a cloud-hosted NoSQL database that stores and
syncs data in realtime across all connected clients.

b) Authentication: Firebase provides a complete authentication system that enables


developers to easily integrate secure sign-in into their app.
c) Cloud Storage: Firebase provides a cloud storage solution for storing user-generated
content such as images, videos, and other media.

d) Cloud Functions: Firebase provides a serverless compute platform that enables


developers to run backend code without having to manage the infrastructure.

e) Analytics: Firebase provides powerful analytics tools that help developers understand
how users are interacting with their app.

f) Crash Reporting: Firebase provides a crash reporting tool that helps developers track and
diagnose app crashes.

g) Performance Monitoring: Firebase provides a tool for monitoring the performance of an


app and identifying areas for optimization.

h) Cloud Messaging: Firebase provides a cloud messaging service that enables developers
to send notifications to their app users.

i) Remote Config: Firebase provides a remote configuration tool that allows developers to
change the behavior and appearance of their app without requiring an app update.

Firebase has a wide range of applications, from simple mobile apps to complex web
applications. Some examples of apps that use Firebase include:

a) Instagram: Instagram uses Firebase's Realtime Database to store and sync user data in
realtime.

b) Shazam: Shazam uses Firebase's Cloud Functions to perform backend processing for its
music recognition service.

c) Duolingo: Duolingo uses Firebase's Cloud Messaging service to send push notifications
to users.

d) The New York Times: The New York Times uses Firebase's Authentication service to
provide secure sign-in for its mobile app.

Overall, Firebase provides a powerful set of tools that can help developers build high-quality
apps quickly and efficiently.

17. What is SQLite database ? Describe its usage with code.


SQLite is a lightweight, open-source, and self-contained database engine that is used by
many Android applications for local data storage. It is a simple and efficient way to store and
manage data on an Android device.
To use SQLite in an Android app, you need to create a helper class that extends the
SQLiteOpenHelper class. This helper class provides methods to create and upgrade the
database, and to perform CRUD (Create, Read, Update, and Delete) operations on the
database. Here is an example of a simple helper class:
public class MyDatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "mydatabase.db";


private static final int DATABASE_VERSION = 1;

public MyDatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String createTableSql = "CREATE TABLE mytable (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)";
db.execSQL(createTableSql);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String dropTableSql = "DROP TABLE IF EXISTS mytable";
db.execSQL(dropTableSql);
onCreate(db);
}
}
In this example, the helper class creates a database with a single table named "mytable" that
has two columns: "_id" and "name".
To perform CRUD operations on the database, you can use the SQLiteDatabase class, which
provides methods to insert, query, update, and delete records. Here are some examples of
how to use the SQLiteDatabase class:

Inserting a record:
SQLiteDatabase db = myDatabaseHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("name", "John");
db.insert("mytable", null, values);

Querying records:
SQLiteDatabase db = myDatabaseHelper.getReadableDatabase();
String[] projection = {"_id", "name"};
Cursor cursor = db.query("mytable", projection, null, null, null, null, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
Log.d(TAG, "id: " + id + ", name: " + name);
}
cursor.close();

Updating a record:
SQLiteDatabase db = myDatabaseHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("name", "Mary");
String selection = "_id = ?";
String[] selectionArgs = {"1"};
db.update("mytable", values, selection, selectionArgs);

Deleting a record:
SQLiteDatabase db = myDatabaseHelper.getWritableDatabase();
String selection = "_id = ?";
String[] selectionArgs = {"1"};
db.delete("mytable", selection, selectionArgs);

These are just a few examples of how to use SQLite in an Android app. With SQLite, you
can create complex databases with multiple tables and relationships between them, and you
can perform advanced queries using SQL.
18. What do you mean by BroadcastReceiver ? Give some examples of Broadcast Receiver ?
Discuss about implementing the registration of a Broadcast Receiver.
BroadcastReceiver is a component in an Android application that allows it to receive and
handle system-wide or application-wide broadcast announcements. It listens to broadcast
announcements sent by the system or other applications and performs a predefined task
based on the broadcast message.
Examples of Broadcast Receivers in Android include:
 Battery status changes
 Network state changes
 Incoming SMS messages
 Device boot completion
 Timezone changes
To implement the registration of a Broadcast Receiver, follow these steps:
 Create a new BroadcastReceiver class by extending the BroadcastReceiver base class and
implementing the onReceive() method.

 Register the BroadcastReceiver in the AndroidManifest.xml file by specifying its name


and the broadcast intent it should listen for.

 Optionally, unregister the BroadcastReceiver when it is no longer needed.


Here is an example of implementing a BroadcastReceiver for listening to changes in network
state:
Create a new Java class, for example, NetworkStateReceiver, that extends the
BroadcastReceiver base class and overrides the onReceive() method:
public class NetworkStateReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// Handle network state changes here
}

}
Register the BroadcastReceiver in the AndroidManifest.xml file by adding the following
code:
<receiver
android:name=".NetworkStateReceiver"
android:enabled="true"
android:exported="true">

<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>

</receiver>
This registers the NetworkStateReceiver to listen for the
android.net.conn.CONNECTIVITY_CHANGE broadcast intent.
Optionally, unregister the BroadcastReceiver when it is no longer needed:
unregisterReceiver(networkStateReceiver);
This removes the registered BroadcastReceiver from the system.
19. What is meant by OkHTTP ? Write down the steps to implement OkHTTP with code
examples.
OkHTTP is a popular HTTP client library used for making network requests in Android
applications. It is a third-party library developed by Square and is widely used due to its ease
of use and high performance.
Here are the steps to implement OkHTTP in an Android project:
Add the OkHTTP dependency to your project's build.gradle file:
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.9.2'
}
Create an instance of the OkHttpClient:
OkHttpClient client = new OkHttpClient();
Create a request object:
Request request = new Request.Builder()
.url("https://jsonplaceholder.typicode.com/posts")
.build();
Create a call object using the client and request:
Call call = client.newCall(request);
Execute the call object and handle the response:
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// Handle network error
}

@Override
public void onResponse(Call call, Response response) throws IOException {
// Handle response data
}
});
In this example, we are making a GET request to the JSONPlaceholder API and handling the
response data in the onResponse() method. The onFailure() method is called if there is a
network error.
OkHTTP also provides additional features such as support for POST requests,
request/response logging, and connection pooling.

Short Notes :

1. Activity LIfeCycle
Activity Lifecycle: The Activity Lifecycle refers to the various states that an activity can go
through during its lifetime. The different states are:
onCreate(): This is the first method that gets called when an activity is created.
onStart(): This method is called when the activity becomes visible to the user.
onResume(): This method is called when the activity is in the foreground and the user can
interact with it.
onPause(): This method is called when the activity is no longer in the foreground, but is still
visible to the user.
onStop(): This method is called when the activity is no longer visible to the user.
onDestroy(): This method is called when the activity is about to be destroyed.

2. Android Emulator
The Android Emulator is a virtual device that allows developers to test their apps without the
need for a physical device. It is included with the Android SDK and can be launched from
within Android Studio. The emulator can be customized to simulate different screen sizes,
hardware configurations, and Android versions.
3. JSON parsing
JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for
humans to read and write, and easy for machines to parse and generate. JSON parsing refers
to the process of extracting data from a JSON file or string and converting it into a format
that can be used in an Android app.
4. Android XML & JSON parsing.
Android XML and JSON Parsing are the two methods of parsing data in Android. XML
(Extensible Markup Language) is a markup language used for storing and transporting data,
while JSON is a lightweight data interchange format. Both XML and JSON can be used to
store data and transfer it between different components in an Android app.
5. Checkbox vs Radio Button
Checkboxes and Radio Buttons are two types of UI elements used in Android apps for user
input. Checkboxes allow the user to select multiple options, while Radio Buttons allow the
user to select only one option. Checkboxes are used when multiple options can be selected,
while Radio Buttons are used when only one option can be selected.
6. List View and Web View
List View and Web View are two UI elements used in Android apps for displaying data. List
View is used to display a list of items, while Web View is used to display web pages. List
View is commonly used in apps that display data in a scrollable list, while Web View is used
to display web content within an app.
7. Activity vs Fragment
Activities and Fragments are two types of components used in Android apps. An Activity
represents a single screen with a user interface, while a Fragment represents a reusable
portion of a user interface that can be combined with other Fragments to create a multi-pane
UI. Activities are typically used for top-level navigation, while Fragments are used for
secondary navigation.
8. Android Jetpack Navigation Component.
The Android Jetpack Navigation Component is a library that helps developers implement
navigation in their apps. It provides a set of tools and APIs for creating and managing
navigation between different screens or destinations in an app. It simplifies the process of
implementing navigation by providing a consistent and predictable user experience.
9. Retrofit Network Library
Retrofit is a type-safe HTTP client for Android and Java that simplifies the process of
making network requests in an Android app. It allows developers to define the API for their
app and generate the necessary code to make requests and parse responses. Retrofit supports
various formats for data exchange, including JSON, XML, and Protocol Buffers.
10. Res folder in Android App Project
The "res" folder in an Android app project contains various resources used in the app, such
as layout files, string resources, drawable resources, and values resources. These resources
are organized into different subfolders
11. Gradle.build

Gradle.build: Gradle.build is a configuration file used in Android development that defines


the build process and dependencies for an Android project. It is written in the Groovy or
Kotlin programming language and is located in the root directory of the project.

12. Permission in Android App.

Permission in Android App: Permissions in Android are used to protect user data and system
resources. The permission system is defined in the AndroidManifest.xml file, where the app
declares the permissions it needs to function properly. At runtime, the app requests
permission from the user, who can choose to grant or deny the permission.

Topic Needs to Cover :

1. https://examradar.com/android-programming-android-architecture-questions-answers/
2. https://examradar.com/android-programming-activity-life-cycle-development-questions-
and-answers/
3. https://examradar.com/android-programming-android-layouts-questions-answers/
4. https://examradar.com/android-programming-android-application-types-questions-
answers/
5. https://examradar.com/android-programming-dalvik-virtual-machine-dvm-questions-
answers/
6. https://examradar.com/android-programming-android-manifest-file-questions-answers/
7. https://examradar.com/android-programming-android-virtual-device-sdk-manager-
questions-answers/
8. https://examradar.com/android-programming-android-fragment-questions-answers/
9. https://examradar.com/android-programming-android-list-view-questions-answers/
10. Intent & Type of Intent
11. How retrofit /okhttp works.
12. How data is fetched using content provider.
13. https://examradar.com/android-programming-json-parsing-android-questions-answers/
14. https://examradar.com/android-programming-xml-parsing-android-questions-answers/
15. Differtent types of views & viewgroup.
16. Widgets in Android
17. Adapter,toast,Alertdialougebuilder,broadcast receiver
18. Firebase & its functionalities
19. Sqlite database & its usage with code
20. Gradle,AVD
Created
Habibiiii……………
Thanks me later <3

You might also like