TY MAD Assignment No 7 & 8
TY MAD Assignment No 7 & 8
Q1. What are Android components and why are they important in an Android application?
Answer:
Android components are the main building blocks of an Android app.
They help the app perform different functions like displaying screens, running tasks, and handling messages.
The main components are Activity, Intent, Service, and Broadcast Receiver.
They are important because without them, the app cannot work properly.
Q2. What is an Activity in Android and what role does it play in an application?
Answer:
An Activity represents a single screen in an Android app.
It is the part where users interact with the app, like entering data or clicking buttons.
Examples include login screen, home screen, or settings screen.
Each activity handles a specific task in the app.
Q3. What is an Intent and how is it used in Android applications?
Answer:
An Intent is a message object used to connect different components of an app.
It helps in starting a new activity or sending data between components.
For example, moving from one screen to another uses Intent.
It makes communication between parts of the app easy.
Q4. What is a Service in Android and when is it used?
Answer:
A Service is a component that runs tasks in the background without user interaction.
It is used for long-running operations like playing music or downloading files.
Services keep running even when the app is not open.
This helps improve user experience.
Q5. What is a Broadcast Receiver and what type of tasks does it perform?
Answer:
A Broadcast Receiver is used to receive and respond to system or app messages.
It reacts to events like battery low, incoming SMS, or network changes.
It works in the background and performs small tasks when an event occurs.
It helps apps respond to real-time changes.
Q6. What is the Activity Life Cycle and what are its main stages?
Answer:
Activity Life Cycle shows the different stages an activity goes through during its lifetime.
Main stages include:
onCreate(): Activity is created
onStart(): Activity becomes visible
onResume(): Activity is active and running
onPause(): Activity is partially hidden
onStop(): Activity is fully hidden
onDestroy(): Activity is removed
These stages help manage resources and user interaction.
Q7. What is the Service Life Cycle and how does a service operate?
Answer:
Service Life Cycle shows how a service starts, runs, and stops.
Main methods include:
onCreate(): Service is created
onStartCommand(): Service starts running in background
onDestroy(): Service is stopped
This helps manage background operations properly.
Q8. What is the life cycle of a Broadcast Receiver and how does it work?
Answer:
Broadcast Receiver has a simple life cycle.
It starts when it receives a broadcast message.
The main method is onReceive(), where the required action is performed.
After completing the task, it stops automatically.
It works quickly and does not run for a long time.
Q9. What are SQLite and Firebase databases and why are they required in Android apps?
Answer:
SQLite: A local database stored on the device
Firebase: A cloud-based database stored online
They are used to store and manage data like user information or app records.
They are required to save data permanently and access it whenever needed.
Q10. How can we create, connect, and retrieve data from SQLite or Firebase database?
Answer:
First, create the database and define tables or collections.
Then connect the app to the database using proper code.
Use commands or methods to insert, update, delete, and fetch data.
Finally, display the retrieved data using UI components like TextView or ListView.