0% found this document useful (0 votes)
5 views13 pages

Notes

The document summarizes the key lifecycle callback methods for Android activities. It describes: 1. The onCreate() method is called when the activity is first created to perform one-time startup logic. 2. The onStart() and onResume() methods are called when the activity becomes visible/interactive, while onPause() and onStop() are called when it becomes non-visible/non-interactive. 3. The onDestroy() method is called before the activity is destroyed to release resources.

Uploaded by

Shivada Jayaram
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)
5 views13 pages

Notes

The document summarizes the key lifecycle callback methods for Android activities. It describes: 1. The onCreate() method is called when the activity is first created to perform one-time startup logic. 2. The onStart() and onResume() methods are called when the activity becomes visible/interactive, while onPause() and onStop() are called when it becomes non-visible/non-interactive. 3. The onDestroy() method is called before the activity is destroyed to release resources.

Uploaded by

Shivada Jayaram
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

onCreate():

1. called when activity is first created.


2. On activity creation, the activity enters the Created state
3. In the onCreate() method, you perform basic application startup logic that should
happen only once for the entire life of the activity.

EG::

onStart():
1. called when activity is becoming visible to the user.
2. The onStart() method completes very quickly and, as with the Created
state, the activity does not stay resident in the Started state.
3. Once this callback finishes, the activity enters the Resumed state, and the
system invokes the onResume() method.
EG:

onResume():
1. called when activity will start interacting with the user
2. The app stays in this state until something happens to take focus away from the
app.
3. When the activity moves to the resumed state, any lifecycle-aware component
tied to the activity's lifecycle will receive the ON_RESUME event.
4. When an interruptive event occurs, the activity enters the Paused state, and the
system invokes the onPause() callback.
EG::

onPause()::
1. called when activity is not visible to the user.
2. Use the onPause() method to pause or adjust operations that should not
continue (or should continue in moderation) while the Activity is in the Paused
state, and that you expect to resume shortly.
EG::

onStop()::
1. called when activity is no longer visible to the user.
2. it has entered the Stopped state, and the system invokes the onStop()
callback.
3. The system may also call onStop() when the activity has finished running,
and is about to be terminated.
4. In the onStop() method, the app should release or adjust resources that are
not needed while the app is not visible to the user
EG::
onRestart()::
1. called after your activity is stopped, prior to start.
EG::

onDestroy()::
1. called before the activity is destroyed.
2. When the activity moves to the destroyed state the activity's lifecycle will
receive the ON_DESTROY event.
3. The onDestroy() callback should release all resources that have not yet been
released by earlier callbacks such as onStop().
EG::

BROADCAST RECEIVER::
Broadcast Receivers simply respond to broadcast messages from other applications or
from the system itself. These messages are sometime called events or intents.

There are following two important steps to make BroadcastReceiver works for the system
broadcasted intents –

1. Creating the Broadcast Receiver.


2. Registering Broadcast Receiver
Registering Broadcast Receiver
An application listens for specific broadcast intents by registering a broadcast
receiver in [Link] file.
BROADCAST SYSTEM EVENTES

SERVICE LIFECYCLE
A service is a component that runs in the background to perform long-running operations without
needing to interact with the user and it works even if application is destroyed. A service can
essentially take two states
ARCHITECTURE
Android operating system is a stack of software components which is roughly divided into
five sections and four main layers as shown below in the architecture diagram.

Linux Kernal:
It is the Bottom Layer, This provides a level of abstraction between the device
hardware and it contains all the essential hardware drivers like camera, keypad,
display etc and also it handles the networking and vast array of the device drivers
Libraries:
On top of Linux kernel there is a set of libraries including open-source Web browser
engine WebKit, SQLite database which is a useful repository for storage and sharing
of application data, libraries to play and record audio and video, SSL libraries
responsible for Internet security etc. Some android libraries are:-
[Link],[Link],[Link],[Link],[Link],etc
Android Runtime:
This is the third section of the architecture .This section provides a key component
called Dalvik Virtual Machine which is a kind of Java Virtual Machine specially designed
and optimized for Android. The DVM makes use of Linux core features like memory
management and multi-threading, etc
It also provides a set of core libraries which enable Android application developers to write
Android applications using standard Java programming language.
Aplication Framework:
VIEWS AND LAYOUTS
1. The basic building block for user interface is a View
2. object which is created from the View class and occupies a rectangular area on the
screen
3. it is responsible for drawing and event handling.
4. View is the base class for widgets, which are used to create interactive UI
components like buttons, text fields, etc.

View group
The View Group is a subclass of View and provides invisible container that hold other
Views or other View Groups and define their layout properties.

Layout
Layout defined in XML. A layout may contain any type of widgets such as buttons,
labels, textboxes, and etc

Layout Types::
[Link] Layout: it is a view group that aligns all children in a single direction,
vertically or horizontally.
[Link] Layout: it is a view group that displays child views in relative positions.
3. Table Layout: it is a view that groups views into rows and columns
4. Absolute Layout: it enables you to specify the exact location of its children.
5. Frame layout: it is a placeholder on screen that you can use to display a single
view.
6. ListView Layout: it is a view group that displays a list of scrollable items.
7. GridView Layout: it is a ViewGroup that displays items in a two-dimensional,
scrollable grid
Layout Attribute:

Common questions

Powered by AI

In the Android Activity Lifecycle, the onPause() and onStop() methods are instrumental in resource management. onPause() is called when the activity is partially obscured and not visible to the user, serving as a cue to pause or adjust resource usage . It enables temporary suspension of processes that might consume CPU or network resources. onStop(), called when an activity is entirely invisible, is used to release resources and save state information that is not needed until the activity becomes visible again. It ensures that applications do not consume unnecessary resources, allowing for efficient memory and system performance .

In the Android Application Framework, ViewGroups are subclasses of View that act as invisible containers for arranging Views or other ViewGroups. They define the layout properties of their child components . ViewGroups dictate the positioning and arrangement of interface elements, with types like LinearLayout and RelativeLayout allowing developers to manage the spatial distribution of widgets on the screen, facilitating complex UIs with interactive, nested View layers .

In Android's UI framework, Linear Layout and Relative Layout offer different layout management strategies. Linear Layout arranges all children elements in a single direction (either vertically or horizontally). This ensures consistent alignment but might not be flexible for complex UIs. Relative Layout, conversely, positions child views relative to their siblings or parent dimensions, providing more dynamic and varied layouts suitable for complex UI designs . This flexibility makes Relative Layout more adaptable to diverse screen sizes and requirements.

The SQLite database is part of the Libraries layer in the Android architecture, providing a lightweight and efficient method of storing and retrieving structured data . It allows applications to manage persistent data efficiently, making it ideal for tasks like maintaining user preferences, caching data, or implementing app-specific databases. As a self-contained SQL database engine, it supports a wide range of SQL syntax, enabling complex queries while ensuring minimal resource consumption, which is critical for mobile applications .

The Dalvik Virtual Machine (DVM) in the Android Runtime is a specialized Java Virtual Machine optimized for Android. It uses Linux core features like memory management and multi-threading to run applications . The DVM is crucial for managing the execution of Android applications, enabling them to run efficiently on the limited resources of mobile devices. Additionally, it provides core libraries that allow developers to use standard Java when writing Android applications, fostering a more seamless development process .

A Broadcast Receiver in Android listens for broadcast messages from other applications or the system, known as intents. To function, it must be created and registered, typically in the AndroidManifest.xml . Unlike other components, Broadcast Receivers do not have a lifecycle that necessitates user visibility or interaction. Instead, they react to broadcasted intents, consuming as little system resources as possible. When a specified event occurs, the receiver's onReceive() method is invoked where it executes limited processing, typically starting a service for more substantial tasks or displaying a notification .

The Linux Kernel is the foundational layer of the Android architecture, providing a critical level of abstraction between device hardware and the operating system . It manages core functionalities such as process management, memory management, and hardware access through essential drivers for components like the camera, keypad, and networking. This abstraction ensures that applications are hardware-independent, allowing Android to run on a wide variety of devices while maintaining security and efficiency .

The onSaveInstanceState() method is crucial in the Activity Lifecycle as it allows an activity to save its current dynamic state, which can be used to restore the activity's state in case it is destroyed and recreated by the system (e.g., during orientation changes). This method is typically used to save UI state changes, such as user inputs or scroll positions, ensuring a seamless user experience when the activity resumes. Without it, users might lose changes if the activity's view hierarchy is recreated during state transitions.

The Android Service Lifecycle is designed for components that run in the background, performing long-running operations without direct user interaction, even if the application is destroyed . In contrast, the Activity Lifecycle directly involves user interaction, with states like onResume() marking when an activity is interactive . Unlike activities, services do not require the application to remain visible, which allows them to continue operations without user intervention. This fundamental difference highlights services' suitability for background processes while activities focus on user-facing interactions.

The onDestroy() method in the Android Activity Lifecycle is pivotal for final cleanup before the activity is destroyed . It releases all resources not already released by prior lifecycle methods like onStop() or onPause(), ensuring no memory leaks or resource wastage when an activity is terminated. This method is invoked either when a user facilitates the destruction (e.g., closing the app) or when the system disposes of the activity to reclaim memory under resource constraints . Proper implementation prevents residual data states or resource locks, which are crucial for maintaining smooth app operation and device performance.

You might also like