0% found this document useful (0 votes)
8 views

Unit II

The document discusses the AndroidManifest.xml file, which contains information about an Android application's package including components like activities, services, and permissions. It also describes the lifecycle methods of Android activities like onCreate(), onStart(), onResume(), etc. Finally, it provides details about the seven standard lifecycle methods and what they do.

Uploaded by

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

Unit II

The document discusses the AndroidManifest.xml file, which contains information about an Android application's package including components like activities, services, and permissions. It also describes the lifecycle methods of Android activities like onCreate(), onStart(), onResume(), etc. Finally, it provides details about the seven standard lifecycle methods and what they do.

Uploaded by

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

Unit-II

AndroidManifest.xml file in android

The AndroidManifest.xml file contains information of your package, including components of the
application such as activities, services, broadcast receivers, content providers etc.

• It performs some other tasks also:

• It is responsible to protect the application to access any protected parts by providing the permissions.

• It also declares the android api that the application is going to use.

• It lists the instrumentation classes. The instrumentation classes provides profiling and other
informations. These informations are removed just before the application is published etc.

Every app project must have an AndroidManifest.xml file (with precisely that name) at the root of the
project source set. The manifest file describes essential information about your app to the Android build tools,
the Android operating system, and Google Play.
Android Activity Lifecycle methods
7 lifecycle methods of android activity.

Method Description

onCreate called when activity is first created.


onStart called when activity is becoming visible to
the user.

onResume called when activity will start interacting


with the user.

onPause called when activity is not visible to the


user.

onStop called when activity is no longer visible to


the user.

onRestart called after your activity is stopped, prior


to start.

onDestroy called before the activity is destroyed.


Understanding Application Priority and Process States
• The order in which processes are killed to reclaim resources is determined by the priority of the hosted
applications. An application’s priority is equal to its highest-priority component. Where two applications
have the same priority, the process that has been at a lower priority longest will be killed first. Process
priority is also affected by inter process dependencies; if an application has a dependency on a Service or
Content Provider supplied by a second application, the secondary application will have at least as high a
priority as the application it supports.
• ❑ Active Processes Active (foreground) processes are those hosting applications with components
currently interacting with the user. These are the processes Android is trying to keep responsive by
reclaiming resources.

• ❑ Visible Processes Visible, but inactive processes are those hosting “visible” Activities. As the name
suggests, visible Activities are visible, but they aren’t in the foreground or responding to user events.
• ❑ Started Service Processes Processes hosting Services that have been started. Services support ongoing
processing that should continue without a visible interface. Because Services don’t interact directly with
the user, they receive a slightly lower priority than visible Activities. They are still considered to be
foreground processes and won’t be killed unless resources are needed for active or visible processes.
• ❑ Background Processes Processes hosting Activities that aren’t visible and that don’t have any Services
that have been started are considered background processes. There will generally be a large number of
background processes that Android will kill using a last-seen-fi rst-killed pattern to obtain resources for
foreground processes.
• ❑ Empty Processes To improve overall system performance, Android often retains applications in
memory after they have reached the end of their lifetimes. Android maintains this cache to improve the
start-up time of applications when they’re relaunched. These processes are routinely killed as required.
• No matter what your development environment, it's always good practice to keep non-code resources
like images and string constants external to your code. Android supports the externalization of
resources ranging from simple values such as strings and colors to more complex resources like images
(Drawables), animations, and themes. Perhaps the most powerful externalizable resources are layouts.

• By externalizing resources you make them easier to maintain, update, and manage. This also lets you
easily define alternative resource values to support different hardware and internationalization.
A Closer Look at Android Activities

• To create user-interface screens for your applications, you extend the Activity class, using Views to
provide user interaction. Each Activity represents a screen (similar to the concept of a Form in desktop
development) that an application can present to its users. The more complicated your application, the
more screens you are likely to need. You’ll need to create a new Activity for every screen you want to
display. Typically this includes at least a primary interface screen that handles the main UI functionality
of your application. This is often supported by secondary Activities for entering information, providing
different perspectives on your data, and supporting additional functionality. To move between screens in
Android, you start a new Activity (or return from one). Most Activities are designed to occupy the entire
display, but you can create Activities that are semitransparent, floating, or use dialog boxes.
Fundamental Android UI Design
User Interface design, human–computer interaction, and usability are huge topics .Android introduces some new terminology for
familiar programming metaphors that will be explored in detail in the following sections:
❑ Views Views are the basic User Interface class for visual interface elements (commonly known as controls or widgets). All
User Interface controls, and the layout classes, are derived fromViews.

❑ ViewGroups View Groups are extensions of the View class that can contain multiple child Views. By extending the
ViewGroup class, you can create compound controls that are made up of interconnected child Views. The ViewGroup class is
also extended to provide the layout managers, such as LinearLayout, that help you compose User Interfaces.

❑ Activities Activities,, represent the window or screen being displayed to the user.
Activities are the Android equivalent of a Form. To display a User Interface, you assign a View or layout to an Activity. Android
provides several common UI controls, widgets, and layout managers.
For most graphical applications, it’s likely that you’ll need to extend and modify these standard controls — or create composite
or entirely new controls — to provide your own functionality
What is Android View?

A View is a simple building block of a user interface. It is a small rectangular box that can
be TextView, EditText, or even a button. It occupies the area on the screen in a rectangular
area and is responsible for drawing and event handling. View is a superclass of all the
graphical user interface components.

Why and How to use the View in Android?

Now you might be thinking what is the use of a View. So, the use of a view is to draw
content on the screen of the user’s Android device. A view can be easily implemented in
an Application using the java code. Its creation is more easy in the XML layout file of the
project. Like, the project for hello world that we had made initially.
Types of Android Views
• Another thing that might now come to your mind must be, “what are the available types of
view in Android that we can use?”
For that, we’ll see all these types one by one as follows:
• TextView
• EditText
• Button
• Image Button
• Date Picker
• RadioButton
• CheckBox buttons
• Image View
What is Android View Group?

• A View Group is a subclass of the ViewClass and can be considered as a superclass of Layouts. It
provides an invisible container to hold the views or layouts. ViewGroup instances and views work
together as a container for Layouts. To understand in simpler words it can be understood as a special
view that can hold other views that are often known as a child view.

• Following are certain commonly used subclasses for ViewGroup:

• LinearLayout

• RelativeLayout

• FrameLayout

• GridView

• ListView
What is Android Layout?

• Layout basically refers to the arrangement of elements on a page these elements are
likely to be images, texts or styles. They define the structure of android user interface in
the app, like in an activity. All elements in the layout are built with the help of Views
and ViewGroups. These layouts can have various widgets like buttons, labels, textboxes,
and many others.
Attributes of Layout in Android
• The following are the attributes for customizing a Layout while defining it:
• android:id: It uniquely identifies the Android Layout.
• android:hint: It shows the hint of what to fill inside the EditText.
• android:layout_height: It sets the height of the layout.
• android:layout_width: It sets the width of the layout.
• android:layout_gravity: It sets the position of the child view.
• android:layout_marginTop: It sets the margin of the from the top of the layout.
• android:layout_marginBottom: It sets the margin of the from the bottom of the
layout.
• android:layout_marginLeft: It sets the margin of the from the left of the layout.
• android:layout_marginRight: It sets the margin of the from the right of the layout.
• android:layout_x: It specifies the x coordinates of the layout.
• android:layout_y: It specifies the y coordinates of the layout.
Types of Layouts in Android
• Linear Layout
• Relative Layout
• Constraint Layout
• Table Layout
• Frame Layout
• List View
• Grid View
• Absolute Layout
• WebView
• ScrollView
1. Linear Layout

• We use this layout to place the elements in a linear manner. A Linear manner means
one element per line. This layout creates various kinds of forms on Android. In this,
arrangement of the elements is in a top to bottom manner.

• This can have two orientations:


a. Vertical Orientation – It is shown above where the widgets such as TextViews, and
all in a vertical manner.
b. Horizontal Orientation – It is shown above where the widgets such as TextViews,
and all in a horizontal manner.
• 2. Relative Layout

• This layout is for specifying the position of the elements in relation to the other
elements that are present there.

• In the relative layout, alignment of the position of the elements to the parent container
is possible. To define it in such a way, we write the following:

• android:layout_alignParentTop= “true”

• android:layout_alignParentLeft= “true”
Introduction to Fragments in Android Applications

• According to the Android documentation, a fragment is a part of applications user


interface that is bound to an activity. Fragments have their lifecycle and layouts or UI
components. Fragments help enrich your UI design, pass data between different
screens, and adapt to different device configurations.

• Unlike activities, fragments are usable. This means that they can be used to showcase
different messages or functions to the user. These functionalities or features allow you
to develop more interactive applications.
What are fragments?

• Before going any further, it’s essential to understand what fragments are or mean. As
we stated above, a fragment is a part of application’s user interface that is bound to an
activity. Fragments also have their logic and can thus, accept and handle different
events. Fragments are beneficial since they allow code to be divided into smaller and
more manageable chunks.

Fragment lifecycle
Adapter

• In Android, Adapter is a bridge between UI component and data source that helps us to
fill data in UI component. It holds the data and send the data to an Adapter view then
view can takes the data from the adapter view and shows the data on different views
like as ListView, GridView, Spinner etc. For more customization in Views we uses the
base adapter or custom adapters.

• To fill data in a list or a grid we need to implement Adapter. Adapters acts like a bridge
between UI component and data source. Here data source is the source from where we
get the data and UI components are list or grid items in which we want to display that
data.
Below is a conceptual diagram of Adapter:
Adapters In Android:
• There are the some commonly used Adapter in Android used to fill the data in the UI
components.
• BaseAdapter – It is parent adapter for all other adapters
• ArrayAdapter – It is used whenever we have a list of single items which is backed by
an array
• Custom ArrayAdapter – It is used whenever we need to display a custom list
• SimpleAdapter – It is an easy adapter to map static data to views defined in
your XML file
• Custom SimpleAdapter – It is used whenever we need to display a customized list and
needed to access the child items of the list or grid
Creating a View Class

A well-designed custom view is much like any other well-designed class. It encapsulates a specific
set of functionality with an easy to use interface, it uses CPU and memory efficiently, and so on. In
addition to being a well-designed class, though, a custom view should:

• Conform to Android standards

• Provide custom styleable attributes that work with Android XML layouts

• Send accessibility events

• Be compatible with multiple Android platforms.

The Android framework provides a set of base classes and XML tags to help you create a view that
meets all of these requirements. This lesson discusses how to use the Android framework to create
the core functionality of a view class.
Subclass a View
All of the view classes defined in the Android framework extend View.
Your custom view can also extend View directly, or you can save time by
extending one of the existing view subclasses, such as Button.
To allow Android Studio to interact with your view, at a minimum
you must provide a constructor that takes a Context and
an AttributeSet object as parameters.
This constructor allows the layout editor to create and edit an instance of
your view.

You might also like