You are on page 1of 6

Android unit 5

Activity Lifecycle and callbacks


Android system initiates its program with an Activity starting with calling
onCreate() callback method. There is a sequence of callback methods that start
up an activity and a sequence of callback methods that tear down an activity as
shown in the below Activity lifecycle diagram:

android_tutorial.pdf page 35 code


android_tutorial.pdf page 40 code
Features of Services:
1. Background Execution:
Services allow tasks to run in the background independently of the user
interface, enabling applications to perform operations, such as data
processing or network transactions, without interrupting the user
experience.
2. Long-Running Operations:
Services are designed for long-running operations, making them suitable for
tasks like music playback, file downloads, or location tracking that need to
continue even when the app is in the background.
3. Lifecycle Management:
Services have a well-defined lifecycle (onCreate, onStartCommand, onBind,
onDestroy), allowing developers to manage resources efficiently and release
them when the service is no longer needed.

Intent
Intent is an object carrying an intent ie. message from one component to
another component with-in the application or outside the application. The
intents can communicate messages among any of the three core components
of an application - activities, services, and broadcast receivers
ACTION:
The action is a string that identifies the operation to be carried out. Common
action examples include opening a web page, sending an email, or playing a
media file.
Actions are the mandatory part of the Intent object and is a string naming the
action to be performed — or, in the case of broadcast intents, it is the action
that took place and is being reported.
ACTION_VIEW:
 Opens the content specified by a URI, such as a web page, image, or
document
ACTION_SEND:
 Sends data to another activity or service, often used for sharing content
like text, images, or files.
ACTION_DIAL:
 Initiates a phone call, allowing the user to dial a specified phone number.
ACTION_CAMERA:
 Opens the device's camera for capturing photos or videos.
ACTION_WEB_SEARCH:
 Performs a web search using the specified query, opening the default
web browser.
ACTION_SENDTO:
 Sends data to a specific recipient, such as an email address or phone
number.
ACTION_BATTERY_CHANGED:
 Broadcast action indicating that the device's battery status has changed,
often used by apps monitoring battery levels.

String url = "https://www.example.com";


// Create an Intent with ACTION_VIEW
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// Start the activity to view the webpage
startActivity(intent);
https://chat.openai.com/share/58b9abdd-8fca-4316-bf9c-024bf85f23eb
What is SQLite?
SQLite is a lightweight, high-performance, and embedded relational database
management system (RDBMS). Unlike traditional RDBMS software like MySQL
or Oracle, SQLite doesn't run as a separate service but rather exists as a library
that gets directly integrated into your application.
"Database package" refers to the Android Framework classes and APIs
provided for interacting with SQLite databases. This package, named
android.database.sqlite, offers functionality for various aspects of database
management, including:
 Creating and opening databases: You can use classes
like SQLiteDatabase and SQLiteOpenHelper to create, open, and manage
connections to your app's SQLite database.
 Defining schemas: You can define your database schema, including
tables, columns, and data types, using SQL statements or helper classes
like SQLiteOpenHelper.onCreate(SQLiteDatabase).
 Executing queries: The package provides methods for executing various
SQL queries like INSERT, UPDATE, DELETE, and SELECT to manipulate data
in your database.
 Fetching results: You can use Cursor objects to iterate through the results
of your queries and access data row by row.
Click to get code for this

You might also like