Unit-2 Android
Unit-2 Android
•Explicit Intents
•Implicit Intents
Explicit Intents
When you explicitly define which Android
component should be opened on some
user action, then you use explicit intents.
You generally use an explicit intent to start
a new component in your own app,
because you know which exact activity or
service you want to start. For example, you
can start a new activity in response to a
user action or start a service to download a
file in the background.
Implicit Intent
When you just have to tell what action you want to
perform without worrying which component will
perform it, then you can use implicit intent.
Implicit intents do not name a specific component to
perform a particular action, but instead it declares a
general action to be performed, which allows any
component, even from another app to handle it.
For example, if you want to show a specific location of
the user on a map, you can use an implicit intent to pass
the coordinates through the intent and then any other
app, which is capable of showing the coordinates on a
map will accept that intent.
Program: Use different Intents in Multiple Activities
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/a
ndroid"
xmlns:app="http://schemas.android.com/apk/res-
auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="55dp"
android:inputType="textPersonName"
android:hint="Name" />
<EditText
android:id="@+id/surname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="SurName" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="65dp"
android:text="save"
android:onClick="save"/>
</LinearLayout>
package com.example.practical_3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myTextView.setElevation(getResources().getDimension(R.dimen.shadow_elevation));
}
}
<resources> <dimen name="shadow_elevation">8dp</dimen> </resources>
Gradients
In Android, gradients can be used to
create smooth color transitions
between two or more colors. There
are two types of gradients in
Android: linear and radial.
Linear gradients are defined by
two points, a start point and an
end point, and can be oriented in
any direction
Applications with multiple screens
Applications with multiple screens
typically refer to apps that have more
than one user interface or view that
users can navigate between. These
apps are often designed to provide a
seamless and intuitive user
experience by allowing users to move
between different sections or
functionalities within the app.
Key concepts related
to applications with
multiple screens in
Android
1.Activities: In Android, screens or user interfaces are typically
implemented using activities. An activity represents a single screen
with a user interface. An app can have multiple activities to
represent different parts of the app's functionality.
2. Navigation: Navigating between screens is a fundamental aspect
of applications with multiple screens. Developers use various
navigation techniques to move from one activity to another.
Common navigation patterns include using buttons, tabs, navigation
drawers, or swipe gestures.
3.Intents: Intents are a way to send requests or messages between
activities. They can be used to start a new activity or to
communicate data between different parts of the app. For example,
you can use an explicit intent to start a specific activity or an implicit
intent to trigger an action, such as opening a web page.
4.Fragments: Fragments are reusable UI components that can be
combined to create flexible and responsive user interfaces. They are
often used within activities to represent parts of the screen that can be
swapped in and out based on user interactions or device orientation
changes.
5.BackStack: The Android platform maintains a back stack to keep track
of the order in which activities are opened. Users can navigate back
through the stack using the device's back button or a navigation toolbar.
Properly managing the back stack is important for providing a consistent
user experience.
6.Tabs and ViewPager: Tabs and ViewPager are common components
for creating apps with multiple screens, especially when dealing with
swipeable or tabbed interfaces. ViewPager allows users to swipe left or
right to switch between different fragments or views.
7.Navigation Components: Android's Navigation Component is a library
that simplifies navigation and screen management, making it easier to
implement complex navigation patterns, such as bottom navigation bars,
navigation drawers, and deep linking.
8.Bottom Navigation: Bottom navigation bars are used
to switch between different top-level destinations in the
app. They often appear at the bottom of the screen and
provide a quick way for users to access different sections
of the app.
9.Drawer Navigation: Navigation drawers slide in from
the side of the screen and are commonly used for
providing access to various app sections or options.
10.Master-Detail Flow: In apps with a master-detail flow,
a list of items is displayed on one screen (the master),
and selecting an item opens a detailed view (the detail)
on another screen. This pattern is often used for tasks
like email clients and contact apps.
Storing and Retrieving data
Storing and retrieving data in an
Android-based application is a
fundamental aspect of app
development. Android provides
several ways to manage data
within an application. Here are
some common methods and
technologies for storing and
retrieving data in Android:
Storing Data:
•SharedPreferences:
•SharedPreferences is a
lightweight and simple way to store
key-value pairs of primitive data
types.
•It's primarily used for storing
small amounts of data like user
preferences, settings, and simple
app configurations.
•Data stored in SharedPreferences
is private to your app and persists
across app sessions.
Internal Storage:
•Internal storage is used for
storing app-specific private files.
•You can save files, such as text
or binary data, directly to your
app's internal storage.
•This storage is not accessible
by other apps.
•External Storage:
•External storage allows you
to store files that are
publicly accessible or shared
among apps if you have the
required permissions.
•It's typically used for larger
files or data that users may
want to access outside of
your app.
•SQLite Database:
•SQLite is a relational database
management system built into
Android.
•It's suitable for managing
structured data, such as user
profiles, inventory, or any data that
requires efficient querying.
•You can create tables, insert,
update, and query data using SQL
statements.
Retrieving Data:
To retrieve data from the storage methods
mentioned above, you generally reverse the
process:
SharedPreferences: Use
getSharedPreferences() and retrieve values
using getString(), getInt(), etc.
Internal Storage: Open the file and read its
contents.
External Storage: Access the file and read its
contents (ensure proper permissions).
SQLite Database: Execute SQL queries using
rawQuery(), query(), or other methods on the
database and process the results using a
Cursor.
Graphics and Multimedia
Graphics and multimedia play a
significant role in enhancing the
user experience of Android web
applications. Android web
applications are typically built using
technologies such as HTML5, CSS,
and JavaScript, which allow
developers to incorporate various
forms of graphics and multimedia
elements
1. Responsive Design: Android web applications
need to adapt to various screen sizes and
orientations. Developers use responsive design
techniques, including media queries in CSS, to
ensure that graphics and multimedia elements
are displayed correctly and efficiently across
different devices and screen resolutions.
2. Performance Optimization: To provide a smooth
user experience, it's essential to optimize the
loading and rendering of graphics and
multimedia content. Techniques such as lazy
loading, image compression, and minimizing the
use of resource-intensive animations can
improve performance.
3. Accessibility: Android web applications should be accessible to
users with disabilities. Developers should provide alternative text
for images, captions or transcripts for multimedia content, and
ensure that interactive elements can be operated using assistive
technologies.
4. Images: Images are essential components of web applications,
and Android web apps are no exception. Developers can use
HTML's <img> tag to display images within the application.
Additionally, CSS can be used to style and position images on the
web page. Images can be static elements or dynamically loaded
from external sources such as web servers or content delivery
networks (CDNs).
5. Videos: Android web applications can embed videos using
HTML5's <video> element. This allows for the playback of both
locally stored and streaming video content. Developers can
control video playback, set playback options (e.g., autoplay,
loop), and provide a customized user interface for video controls.
6. Videos: Android web applications can embed videos using
HTML5's <video> element. This allows for the playback of both
locally stored and streaming video content. Developers can
control video playback, set playback options (e.g., autoplay,
loop), and provide a customized user interface for video
controls.
7. Audio: Similarly, audio can be integrated into Android web
applications using the <audio> element in HTML5. This enables
the playback of audio files, background music, or audio effects.
Developers can also control audio playback, adjust volume, and
provide custom audio player controls.
8. Canvas and WebGL: For more advanced graphics and
animations, Android web applications can use the <canvas>
element in HTML5 and WebGL (Web Graphics Library). These
technologies provide a powerful way to create interactive and
dynamic graphics, including games and visualizations.
Developers can use JavaScript to manipulate and draw on the
Location based services
Location-based services (LBS) in Android
refer to a set of features and capabilities
that allow Android devices to determine
and use their geographic location to
provide information, services, or
functionality based on that location. These
services rely on the device's built-in GPS
(Global Positioning System), Wi-Fi, cellular
network, or other sensors to determine the
user's current location.
features of location-based services in Android include