0% found this document useful (0 votes)
42 views14 pages

Comprehensive Questions

This document contains 90 theoretical questions and answers for an Android Development exam, covering various topics including permissions, background tasks, AsyncTasks, BroadcastReceivers, and AlertDialogs. Each question is bolded with clear, detailed answers suitable for 3-4 mark questions, including code snippets where relevant. The first 80 questions focus on general Android development concepts, while the last 10 specifically address Android Notifications.

Uploaded by

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

Comprehensive Questions

This document contains 90 theoretical questions and answers for an Android Development exam, covering various topics including permissions, background tasks, AsyncTasks, BroadcastReceivers, and AlertDialogs. Each question is bolded with clear, detailed answers suitable for 3-4 mark questions, including code snippets where relevant. The first 80 questions focus on general Android development concepts, while the last 10 specifically address Android Notifications.

Uploaded by

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

Theoretical Questions and Answers for

Android Development Exam


Note: This document has 90 theoretical questions with detailed answers for your exam. Each
question is bold, and answers are clear, simple, and long enough for 3–4 mark questions. Small
code snippets are included where helpful. The first 80 questions cover eight topics from your
files, and the last 10 cover Android Notifications. Copy this into a Word document, format with
bold questions, and study. Good luck!

Document 1: AndroidPermissions.pptx
Q1: What are permissions in Android?​
Permissions are rules that decide what an app can do, like using the camera or reading
contacts. They protect user privacy by limiting access to sensitive data or features. For example,
an app needs permission to access your location to show nearby places. Without permissions,
apps could misuse your data, so Android makes sure users approve risky actions.

Q2: Why did Android introduce runtime permissions?​


Runtime permissions started in Android 6.0 (Marshmallow) to give users more control over
apps. Before, permissions were granted when installing the app, which could allow misuse.
Now, apps ask for permissions when needed, like requesting camera access when you take a
photo. This makes apps safer and lets users decide what to allow. For example:

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 101);

Q3: What is the difference between normal and dangerous permissions?​


Normal permissions are safe and automatically granted, like accessing the internet, because
they don’t harm user privacy. Dangerous permissions, like camera or storage access, are risky
and need user approval at runtime. For example, an app can use the internet without asking,
but it must request permission to read your photos. This protects sensitive data from
unauthorized access.

Q4: What is the permission request flow in Android?​


The permission request flow checks if a permission is granted, asks the user if not, and handles
their response. First, the app checks if it has permission (e.g., for location). If not, it shows a
dialog asking the user to approve or deny. The app then acts based on the user’s choice, like
disabling a feature if denied. This ensures users control what apps can do.

Q5: How does Android 13 handle storage permissions differently?​


Android 13 replaced the old READ_EXTERNAL_STORAGE permission with specific ones:
READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, and READ_MEDIA_AUDIO. This gives users
finer control, so an app can access only images, not all files. For example, a gallery app only
needs READ_MEDIA_IMAGES. This change improves privacy by limiting access to specific
media types. Code example:

requestPermissionLauncher.launch(Manifest.permission.READ_MEDIA_IMAGES);

Q6: What is the "Don't Ask Again" scenario in permissions?​


If a user denies a permission and checks “Don’t Ask Again,” the app can’t request it again. The
app must guide the user to the settings to enable it manually. This stops apps from annoying
users with repeated requests. For example, a camera app might show a message to open
settings if the camera permission is blocked. This respects user choices.

Q7: Why should apps explain permissions to users?​


Explaining permissions tells users why the app needs access, building trust. For example, a
photo app might say, “We need camera access to take pictures.” This makes users feel safe
and more likely to approve. Without explanations, users might deny permissions, thinking the
app is suspicious. A custom dialog before the system dialog works best.

Q8: What happens if a permission is denied in an app?​


If a permission is denied, the app should reduce features gracefully, like disabling the camera if
camera access is denied. It should also show a message, like “Please allow camera access to
take photos.” This prevents the app from crashing and keeps the user informed. Good apps
offer alternatives, like using saved photos instead of taking new ones.

Q9: What is the purpose of background location permission?​


Background location permission (ACCESS_BACKGROUND_LOCATION) lets apps access
location when not in use, like for tracking delivery. Since Android 10, it needs special approval
because it’s very sensitive. Users must explicitly allow it in settings, ensuring privacy. For
example, a navigation app needs this to track your route in the background.

Q10: Why are permissions important for user privacy?​


Permissions protect user privacy by controlling what apps can access, like contacts or location.
They ensure apps only use data with user approval, preventing misuse. For example, a game
shouldn’t access your messages without permission. Runtime permissions let users decide,
making Android safer. This builds trust between users and apps.

Document 2: Handling BackGround Tasks in Android.pdf


Q11: What are background tasks in Android?​
Background tasks are jobs that run without showing on the screen, like downloading files or
playing music. They let apps work while users do other things. For example, a music app plays
songs in the background. Android controls these tasks to save battery and keep the phone fast.
Good background tasks don’t slow down the device.
Q12: What is the purpose of Android Services?​
Services run long tasks in the background, like syncing data or playing music, even if the app’s
screen is closed. They don’t have a user interface and can work independently. For example, a
music app uses a service to keep playing songs. Services are useful when tasks need to
continue without user interaction. They’re managed by Android to ensure smooth performance.

Q13: What is WorkManager used for?​


WorkManager schedules tasks that can wait, like uploading logs or syncing data, and runs them
even if the app closes or the phone restarts. It’s great for tasks that don’t need to happen
instantly, like sending reports when Wi-Fi is available. WorkManager saves battery by choosing
the best time to run. For example:

MyWorkManager.enqueueWork();

Q14: Why is AsyncTask not good for long tasks?​


AsyncTask is meant for short tasks, like fetching small data, because it’s tied to the app’s
screen. Long tasks can cause errors, like memory leaks, if the screen closes. For example,
downloading a big file might fail if the user exits the app. AsyncTask is also deprecated, so
WorkManager is better for reliability. It’s best for quick updates to the UI.

Q15: What does JobScheduler do?​


JobScheduler plans tasks to run later, like periodic data uploads, and optimizes them to save
battery. It waits for the right conditions, like Wi-Fi or charging, to run tasks efficiently. For
example, an app might schedule nightly backups. JobScheduler is managed by Android to avoid
draining the phone. It’s great for non-urgent tasks.

Q16: What are Foreground Services?​


Foreground Services run important tasks that users notice, like music playback, and show a
notification to indicate they’re active. They’re less likely to be stopped by Android because
they’re visible. For example, a music app shows a “Playing” notification. They’re used for tasks
that must keep running. Code example:

startForeground(1, notification);

Q17: Why does Android limit background tasks?​


Since Android 8.0, background tasks are limited to save battery and improve phone speed.
Running too many tasks can drain power or slow the device. For example, apps can’t freely
sync data in the background anymore. Android forces apps to use tools like WorkManager or
Foreground Services. This keeps the phone efficient for users.

Q18: What is the benefit of WorkManager over Services?​


WorkManager guarantees tasks will finish, even if the app closes or the phone restarts, unlike
regular Services. It also optimizes tasks to run when the phone isn’t busy, saving power. For
example, WorkManager can upload photos when charging. Services might stop if the app is
killed, but WorkManager persists. It’s easier to use for delayed tasks.
Q19: When should you use Thread/Executor?​
Thread/Executor is used for complex tasks needing precise control, like downloading multiple
files at the same time. They let developers manage how tasks run, unlike WorkManager’s
automatic scheduling. For example, an app might use Executor to process images in parallel.
However, developers must handle errors carefully to avoid crashes. Code example:

ExecutorService executor = Executors.newFixedThreadPool(3);

Q20: Why is AsyncTask deprecated?​


AsyncTask is deprecated since API 30 because it can cause memory leaks or errors if the app’s
screen closes during a task. It’s not reliable for modern apps with complex needs. For example,
rotating the phone might break an AsyncTask. Alternatives like WorkManager or Kotlin
Coroutines are safer and more flexible. Developers should avoid AsyncTask for new projects.

Document 3: AsynTasks_Android.pdf
Q21: What is an AsyncTask in Android?​
AsyncTask is a tool to run short background tasks, like downloading data, and update the app’s
screen when done. It keeps the app smooth by avoiding work on the main thread, which
handles the display. For example, an app might use AsyncTask to fetch news and show it. It’s
easy for beginners but not good for long tasks. Code example:

new FetchDataTask().execute("https://example.com");

Q22: Why is the main thread important in Android?​


The main thread manages the app’s display and user actions, like tapping buttons. If long tasks
run on it, the app freezes or shows an error (ANR). For example, downloading a file on the main
thread stops the app from responding. Tools like AsyncTask move work to the background to
keep the app smooth. The main thread must stay free for a good user experience.

Q23: What are the three generic types in AsyncTask?​


AsyncTask uses three types: Params (input, like a URL), Progress (updates, like percentage
done), and Result (output, like fetched data). They define what the task takes, shows, and
returns. For example, a task fetching a string from a URL uses String as Params and Result.
These types make AsyncTask flexible for different tasks. They help organize the task’s flow.

Q24: What does the onPreExecute method do?​


onPreExecute runs on the main thread before the task starts, setting up things like showing a
loading spinner. It prepares the app’s screen for the task. For example, it might display
“Loading…” to inform the user. It’s useful for making the app feel responsive. Code example:

progressBar.setVisibility(View.VISIBLE);

Q25: What is the purpose of doInBackground?​


doInBackground runs the main task in the background, like fetching data or processing files,
without freezing the app. It keeps the main thread free for user actions. For example, it might
download a file from a URL. It’s the core of AsyncTask where heavy work happens. Code
example:

String data = downloadFromUrl(params[0]);

Q26: When is onProgressUpdate called?​


onProgressUpdate runs on the main thread when the task reports progress, like updating a
progress bar. It’s triggered by calling publishProgress in doInBackground. For example, a
download task might show “50% done.” It keeps users informed during long tasks. It makes the
app feel interactive and responsive.

Q27: What happens in onPostExecute?​


onPostExecute runs on the main thread after doInBackground finishes, showing the task’s result
on the screen. For example, it might display fetched data in a text box. It also hides loading
indicators to clean up. It’s key for updating the app’s display safely. Code example:

textViewResult.setText(result);

Q28: Why can AsyncTask cause memory leaks?​


AsyncTask holds a reference to the activity, so if the activity is destroyed (e.g., during screen
rotation) while the task runs, it can leak memory. This wastes phone resources and may crash
the app. For example, a long download might keep a closed activity in memory. Using static
classes or WeakReference prevents this. Modern alternatives like WorkManager avoid these
issues.

Q29: What is the onCancelled method used for?​


onCancelled runs on the main thread if the task is stopped, allowing cleanup like hiding a
progress bar. It’s called when cancel(true) stops the task. For example, if a user stops a
download, onCancelled updates the screen. It ensures the app stays tidy after cancellation. It’s
important for a smooth user experience.

Q30: Why should you avoid AsyncTask for long tasks?​


AsyncTask is for short tasks (a few seconds), like fetching small data, because long tasks can
fail if the app closes. It’s tied to the activity, so screen changes can cause errors. For example, a
big file download might stop if the user exits. WorkManager is better for long or reliable tasks.
AsyncTask’s deprecation also pushes developers to newer tools.

Document 4: BroadcastRecievers.pptx
Q31: What is a BroadcastReceiver in Android?​
A BroadcastReceiver listens for messages (broadcasts) from Android or apps, like low battery or
Wi-Fi changes. It lets apps react to events without a screen. For example, an app might show a
warning when the battery is low. It’s a key component for handling system or app events. It
works quietly in the background.
Q32: What are the two types of broadcasts?​
System broadcasts are sent by Android, like BOOT_COMPLETED when the phone starts or
BATTERY_LOW. Custom broadcasts are sent by apps to communicate internally, like notifying a
new message. For example, a chat app might send a custom broadcast for a new chat. Both
types help apps stay updated. They’re handled by BroadcastReceivers.

Q33: Why don’t BroadcastReceivers have a user interface?​


BroadcastReceivers only process quick messages and don’t need a screen to show users.
They’re meant to react silently, like logging a battery low event. For example, a receiver might
save data without displaying anything. If a UI is needed, they trigger activities or notifications.
This keeps them fast and efficient.

Q34: What is static registration for BroadcastReceivers?​


Static registration is defined in the app’s manifest to listen for broadcasts even when the app is
closed. It’s used for system events, like BOOT_COMPLETED, to start tasks after a reboot. For
example, an app might check updates on boot. It needs permissions for protected broadcasts.
Code example:

<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

Q35: What is dynamic registration?​


Dynamic registration is done in code, usually in an activity, to listen for broadcasts while the app
runs. It’s flexible for temporary needs, like detecting airplane mode changes. For example, an
app might show a message when airplane mode is on. It must be unregistered when the activity
stops to avoid errors. It’s good for short-term events.

Q36: Why should BroadcastReceivers execute quickly?​


BroadcastReceivers must finish fast (within seconds) to avoid slowing the Android system. Long
tasks can delay other apps or drain the battery. For example, a receiver handling a low battery
event should quickly log it. Heavy work should move to a Service. This keeps the phone
responsive.

Q37: What happens if you don’t unregister a dynamic receiver?​


Not unregistering a dynamic receiver causes memory leaks because it keeps running after the
activity closes. This wastes phone memory and may crash the app. For example, a receiver for
Wi-Fi changes might stay active unnecessarily. Always call unregisterReceiver in onDestroy.
This ensures the app runs smoothly.

Q38: What is LocalBroadcastManager used for?​


LocalBroadcastManager sends broadcasts within the app securely, preventing other apps from
accessing them. It’s faster and safer than system broadcasts for internal communication. For
example, an app might notify its parts about a new setting. It’s deprecated now, so LiveData or
StateFlow is recommended. It was useful for app-only events.

Q39: Why are permissions needed for some broadcasts?​


Permissions protect sensitive broadcasts, like BOOT_COMPLETED, so only authorized apps
can listen. This prevents malicious apps from misusing system events. For example,
RECEIVE_BOOT_COMPLETED permission ensures only trusted apps act on boot. It keeps the
system secure. Without permissions, privacy could be at risk.

Q40: How do background limits affect BroadcastReceivers?​


Since Android 8.0, background limits restrict BroadcastReceivers to save battery and improve
performance. Apps in the background can’t freely receive broadcasts, like connectivity changes.
For example, an app might not react to Wi-Fi changes unless active. Developers must use
WorkManager or Foreground Services instead. This makes phones more efficient.

Document 5: AlertDialogus.pdf
Q41: What is an AlertDialog in Android?​
An AlertDialog is a pop-up box that shows messages or asks users to choose, like OK or
Cancel. It’s used for warnings, confirmations, or simple inputs. For example, it might ask, “Do
you want to delete this file?” It’s simple and doesn’t need a full screen. It’s a common way to talk
to users.

Q42: What is the purpose of setTitle in AlertDialog?​


setTitle sets the heading of the AlertDialog, like “Error” or “Confirm.” It tells users the dialog’s
purpose clearly. For example, a title “Warning” alerts users to pay attention. It makes the dialog
easy to understand. Code example:

builder.setTitle("Confirmation");

Q43: What does setMessage do in AlertDialog?​


setMessage shows the main text in the AlertDialog, explaining what’s happening or what the
user needs to do. For example, it might say, “Are you sure you want to exit?” It gives context for
the user’s choice. It’s the core information in the dialog. Clear messages improve user
experience.

Q44: What are positive and negative buttons in AlertDialog?​


Positive buttons, like OK, confirm the user’s action, such as saving a file. Negative buttons, like
Cancel, dismiss the dialog without action. For example, a dialog might ask to delete a photo with
OK to delete and Cancel to stop. They guide user decisions. They’re standard for user input.

Q45: What is a DialogFragment?​


A DialogFragment is a dialog that acts like a fragment, managing its own lifecycle for reuse
across the app. It’s better than AlertDialog for complex dialogs, like those with custom layouts.
For example, a login dialog can be reused in multiple screens. It handles changes like screen
rotation automatically. It’s great for stable dialogs.

Q46: What is a single choice dialog?​


A single choice dialog lets users pick one option from a list, like choosing a language. It’s useful
for settings where only one choice is allowed. For example, selecting “English” from a list of
languages. It simplifies user decisions. It’s a clean way to offer limited options.

Q47: What is a multiple choice dialog?​


A multiple choice dialog allows users to select several options from a list, like choosing hobbies.
It’s good for collecting multiple inputs, like selecting favorite foods. For example, a user might
pick “Pizza” and “Burger.” It’s flexible for complex choices. It’s user-friendly for multi-select
needs.

Q48: Why use a custom layout in AlertDialog?​


A custom layout adds complex elements, like text fields or images, to an AlertDialog for richer
user input. For example, a login dialog might include username and password fields. It makes
dialogs more interactive than simple messages. It’s useful when standard buttons aren’t
enough. It enhances user engagement.

Q49: How does DialogFragment handle device rotation?​


DialogFragment automatically saves and restores its state during rotation, keeping the dialog
visible. Unlike AlertDialog, it doesn’t disappear when the screen changes. For example, a form
dialog stays open after rotating the phone. This makes it reliable for complex dialogs. It
improves app stability.

Q50: Why might a dialog need permissions?​


Dialogs that trigger sensitive actions, like accessing the camera, need permissions to ensure
user approval. For example, a dialog asking to take a photo must check camera permission first.
This respects privacy and follows Android rules. Without permissions, the dialog’s action might
fail. It keeps the app secure.

Document 6: Deploying ML-Model on Android App.pptx


Q51: What is TensorFlow Lite used for?​
TensorFlow Lite is a tool to run machine learning models on Android for fast predictions. It’s
lightweight, so it works well on phones with limited power. For example, an app might use it to
classify flowers from photos. It’s designed for mobile apps, unlike full TensorFlow. It makes
smart features possible on Android.

Q52: Why can’t RandomForestClassifier be used with TensorFlow Lite?​


RandomForestClassifier is a scikit-learn model, not built with TensorFlow, so it’s not compatible
with TensorFlow Lite. TensorFlow Lite only supports TensorFlow models, like neural networks.
For example, a RandomForest model can’t run on Android directly. Developers must convert
models to .tflite format first. This limits traditional ML models on mobile.
Q53: What is the Iris dataset used for?​
The Iris dataset contains flower measurements, like petal length, to train models for
classification. It’s a simple dataset with three flower types (e.g., Iris-setosa). For example, a
model learns to predict the flower type from measurements. It’s popular for testing machine
learning. It’s easy for beginners to understand.

Q54: What does LabelEncoder do in machine learning?​


LabelEncoder converts text labels, like flower names, into numbers for model training. Machines
understand numbers, not text, so it’s necessary. For example, it changes “Iris-setosa” to 0 and
“Iris-versicolor” to 1. It makes data ready for algorithms. Code example:

le = LabelEncoder()
data['Species'] = le.fit_transform(data['Species'])

Q55: Why remove the Id column from the Iris dataset?​


The Id column is just a unique number for each row and doesn’t help predict the flower type.
Removing it focuses the model on useful features, like petal width. For example, including Id
could confuse the model. It keeps training accurate. It’s a common step in data preparation.

Q56: What is the purpose of train_test_split?​


train_test_split divides data into training and testing sets to check how well the model works.
The training set teaches the model, and the testing set evaluates it. For example, 80% of Iris
data trains the model, and 20% tests its accuracy. It prevents overfitting. Code example:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

Q57: Why is model conversion needed for Android?​


Models must be converted to .tflite format to run efficiently on Android’s limited resources. .tflite
is optimized for mobile, unlike desktop models. For example, a TensorFlow model is too big but
converts to a smaller .tflite file. Conversion ensures fast predictions. It’s key for mobile ML apps.

Q58: What does the Android app do with a .tflite model?​


The app takes user input, runs the .tflite model, and shows the prediction, like identifying a
flower. For example, users enter petal measurements, and the app predicts “Iris-setosa.” It uses
TensorFlow Lite to process the model quickly. The result might show in a Toast message. It
makes apps smart and interactive.

Q59: Why use Jupyter Notebook for model training?​


Jupyter Notebook is an easy tool to write, test, and visualize Python code for training models. It
lets developers see data, like Iris measurements, and results step-by-step. For example, you
can plot accuracy in a graph. It’s beginner-friendly and widely used. It speeds up model
development.

Q60: What is the role of build.gradle in ML deployment?​


build.gradle adds TensorFlow Lite libraries to the Android app, enabling model use. It lists
dependencies, like ‘org.tensorflow:tensorflow-lite:2.10.0’. For example, without it, the app can’t
run .tflite models. It’s a key setup step in Android Studio. It connects the app to ML tools.

Document 7: Firebase_.docx
Q61: What is Firebase in Android?​
Firebase is a Google platform that provides tools, like databases and login systems, to build
better Android apps. It simplifies tasks like storing data online or signing in users. For example,
a contact app uses Firebase to save contacts on the cloud. It’s easy to set up and works across
devices. It reduces complex coding for developers.

Q62: What is the google-services.json file?​


google-services.json is a file that links your Android app to a Firebase project. It contains details
like the project ID and API key. For example, it’s placed in the app/ folder to connect to Firebase
Database. Without it, the app can’t use Firebase features. It’s a critical setup step.

Q63: Why is Firebase Database useful?​


Firebase Database stores data online, so apps can access it from anywhere without a local
server. It syncs data across devices instantly, like updating contacts on all phones. For example,
a user adds a contact, and it appears on their tablet. It’s easy to use and secure. It’s great for
real-time apps.

Q64: What are CRUD operations in Firebase?​


CRUD stands for Create, Read, Update, Delete—ways to manage data in Firebase. Create
adds new data, Read retrieves it, Update changes it, and Delete removes it. For example, an
app creates a contact, reads all contacts, updates a phone number, or deletes a contact. These
operations handle all data tasks. They’re the backbone of database apps.

Q65: What is a DatabaseReference in Firebase?​


DatabaseReference points to a specific spot in the Firebase Database, like the “contacts” folder.
It’s used to read or write data at that location. For example, to add a contact, you use
DatabaseReference to target “contacts/contactId1”. It’s like an address for data. Code example:

databaseReference = database.getReference("contacts");

Q66: Why use a Contact model class with Firebase?​


The Contact class defines how data, like name and phone, is structured for Firebase. It ensures
data is saved and read correctly in the database. For example, a Contact object with “John” and
“123456789” matches the database format. It simplifies coding and avoids errors. It’s essential
for organized data.

Q67: What does push().getKey() do in Firebase?​


push().getKey() creates a unique ID for new data in Firebase, like a new contact. It ensures
each entry has a different ID to avoid conflicts. For example, adding a contact generates a
random ID like “contactId1”. It makes data management automatic and safe. Code example:
String contactId = databaseReference.push().getKey();

Q68: Why sync Gradle after adding Firebase?​


Syncing Gradle updates the app to include Firebase libraries, like database or authentication
tools. Without syncing, the app can’t use Firebase features. For example, it loads
‘com.google.firebase:firebase-database:20.1.0’. It’s done in Android Studio after editing
build.gradle. It ensures the app is ready for Firebase.

Q69: What is a ValueEventListener in Firebase?​


ValueEventListener listens for changes in Firebase data and retrieves the updated data. For
example, when a contact is added, it fetches the new list. It runs whenever data changes,
keeping the app current. It’s key for real-time updates. Code example:

databaseReference.addValueEventListener(listener);

Q70: Why is Firebase good for contact management?​


Firebase stores contacts online, syncs them across devices, and simplifies adding, updating, or
deleting them. It doesn’t need a complex server, unlike local databases. For example, a user
edits a contact on their phone, and it updates on their laptop. It’s secure and easy to use. It’s
perfect for apps needing cloud data.

Document 8: SQLite_.docx
Q71: What is SQLite in Android?​
SQLite is a small, built-in database for storing app data locally, like contacts or notes, without
needing the internet. It’s lightweight and fast, perfect for mobile apps. For example, a contact
app saves names and phones in SQLite. It uses SQL queries to manage data. It’s included in
every Android device.

Q72: Why is SQLite good for apps?​


SQLite is simple, needs no server, and stores data permanently on the phone. It’s great for apps
that work offline, like a to-do list app. For example, contacts saved in SQLite stay even if the app
closes. It’s fast and uses little space. It’s a reliable choice for local storage.

Q73: What is SQLiteOpenHelper?​


SQLiteOpenHelper is a class that sets up and manages the SQLite database in Android. It
creates tables and updates the database when needed. For example, it makes a “contacts”
table when the app first runs. It simplifies database tasks for developers. It’s essential for SQLite
apps.

Q74: What is the purpose of Params.java?​


Params.java stores fixed values, like the database name or table name, to avoid mistakes in
code. It keeps things organized and easy to change. For example, it defines “contacts_db” as
the database name. It prevents errors from typing values repeatedly. Code example:
public static final String DB_NAME = "contacts_db";

Q75: What is a Contact model class in SQLite?​


The Contact class defines the structure of a contact, like id, name, and phone, for SQLite
storage. It makes saving and reading data consistent. For example, a Contact object holds
“John” and “123456789” for the database. It’s a simple way to represent data. It’s key for clear
data handling.

Q76: What are CRUD operations in SQLite?​


CRUD means Create, Read, Update, Delete—ways to work with SQLite data. Create adds a
new contact, Read gets all contacts, Update changes a phone number, and Delete removes a
contact. For example, an app uses CRUD to manage a contact list. These operations cover all
database needs. They’re standard for data apps.

Q77: What does onCreate do in SQLiteOpenHelper?​


onCreate runs when the database is first made, creating tables like “contacts” with columns for
id, name, and phone. It sets up the database structure. For example, it builds a table to store
contact data. It only runs once at the start. It’s critical for initializing the database.

Q78: What is the role of onUpgrade in SQLiteOpenHelper?​


onUpgrade updates the database when its version changes, like adding new columns. It deletes
old tables and recreates them with the new structure. For example, it might add an “email”
column to the contacts table. It ensures the database stays current. It runs automatically during
upgrades.

Q79: Why use ContentValues in SQLite?​


ContentValues stores data in a key-value format, like “name” and “John,” for adding or updating
in SQLite. It makes saving data simple and safe. For example, it’s used to insert a new contact.
It avoids writing complex SQL queries. Code example:

values.put(Params.KEY_NAME, contact.getName());

Q80: What is a Cursor in SQLite?​


A Cursor reads data from SQLite query results, like a list of contacts. It moves through rows to
access each contact’s details, like name and phone. For example, it fetches all contacts to
display in a list. It’s the main way to get database data. It’s essential for reading operations.

Document 9: Android Notifications


Q81: What are messages in Android apps?​
Messages (notifications) are small alerts that tell users about app events, like a new text or a
finished download. They appear at the top of the phone or in a list called the notification drawer.
For example, a chat app sends a message when you get a new text. They keep users updated
even when the app is closed. They make apps more helpful and interactive.
Q82: How do messages help background jobs?​
Messages show users that background jobs, like playing music or downloading files, are
running or done. For example, a music app shows a message saying “Playing Song” while it
runs in the background. They also tell users when a scheduled job, like a backup, finishes. This
keeps users informed and follows Android’s rules. Messages make background jobs clear to
users.

Q83: What are the main types of messages in Android?​


Basic messages show simple text, like “New Email.” Progress messages show a bar for tasks,
like downloading a file. Action messages have buttons, like “Reply” for a text. Pop-up messages
appear on the screen for urgent alerts, like a call. Each type helps users in different ways,
making apps easy to use.

Q84: Why do important background jobs need messages?​


Since Android 8.0, important background jobs (Foreground Services) must show a message to
tell users what’s happening, like “Music Playing.” This stops Android from closing the job and
keeps users aware. For example, a music app shows a message so the song keeps playing. It
follows Android’s rules and improves trust. Without messages, the job might stop.

Q85: What permission is needed to show messages?​


The POST_NOTIFICATIONS permission is needed for Android 13 and above to show any
message. Apps must ask users for this permission when they want to send a message. For
example, a chat app needs it to alert you about new texts. It keeps users in control of what apps
can show. Code example:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Q86: What is a message group, and why is it needed?​


A message group (notification channel) is a category, like “Chat Alerts,” that organizes
messages. Since Android 8.0, every message needs a group so users can change settings, like
turning off sound for some alerts. For example, you can mute game alerts but keep chat alerts
loud. It gives users control and is required by Android. Code example:

NotificationChannel channel = new NotificationChannel("chat", "Chat Alerts",


NotificationManager.IMPORTANCE_DEFAULT);

Q87: How do you make a simple message?​


To make a simple message, set an icon, title (like “New Text”), and text (like “From John”). Add a
tap action to open the app when clicked, and show it using Android’s message system. For
example, a chat app shows “New Message” that opens the chat when tapped. It needs the
POST_NOTIFICATIONS permission for Android 13. It’s a basic way to alert users.

Q88: How do you make a progress message?​


A progress message shows a bar for tasks, like downloading a file. You set a title (like
“Downloading”), a bar that updates (e.g., 50% done), and show it. For example, a download app
shows a bar that fills up. It needs the POST_NOTIFICATIONS permission for Android 13. It
keeps users updated on long tasks.

Q89: How do you add a button to a message?​


To add a button, like “Reply,” to a message, include an action with a title and what happens
when clicked (e.g., open a reply screen). For example, a chat app shows a “Reply” button to
type a quick reply. It needs the POST_NOTIFICATIONS permission for Android 13. Buttons
make messages interactive. They let users act without opening the app.

Q90: What are the best ways to make good messages?​


Use clear, short titles and text, like “New Email” instead of long sentences. Always use a
message group for Android 8.0 and above so users can adjust settings. Ask for
POST_NOTIFICATIONS permission in Android 13. Don’t send too many messages to avoid
annoying users. For example, group similar alerts, like multiple texts, into one message to keep
things tidy.

You might also like