Ap Unit-2
Ap Unit-2
1
DESIGN CRITERIA FOR
ANDROID APPLICATION
Hardware Design Consideration
Compared to desktop or laptop computers, mobile
devices have relatively:
Low processing power
Limited RAM
2
DESIGN DEMANDS FOR ANDROID
APPLICATION
3
ACTIVITY AND ACTIVITY LIFE CYCLE
Activity:
An activity represents a single screen with a user
interface.
For example, an email application might have
one activity that shows a list of new emails,
another activity to compose an email, and
another activity for reading emails.
Generally, one screen implements one screen
in an app.
4
If you have worked with C, C++ or Java
programming language then you must have seen
that your program starts from main() function.
Very similar way, Android system initiates its
program with in an Activity starting with a call on
onCreate() callback method.
5
ACTIVITY LIFE CYCLE OF ANDROID
6
CALL BACK METHODS
8
onStop(): Called when the activity is no longer visible to
the user
onDestroy(): Called before the activity is destroyed by
the system
onRestart(): Called when the activity has been stopped
and is restarting again
CREATING APPLICATION AND NEW
ACTIVITIES
Programmatically create
Using Menubar
9
MANIFEST FILE
The AndroidManifest.xml file contains detailed
configuration information for your application.
Every app project must have an
AndroidManifest.xml file 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.
10
INTENT
Intent provides navigation between application
components.
It is used to start a new activity from where
ever you are.
Intents are also used to tell the system, which
is the entry point of your application inside of
your application, and which activity should
appear in launcher screen.
Types of Intents
1. Explicit Intents
2. Implicit Intents
11
EXPLICIT INTENT
These intents designate the target component by its
name and they are typically used for application-internal
messages - such as an activity starting a subordinate
service or launching a another activity.
For Example:
// Explicit Intent by specifying its class name
Intent i = new Intent(FirstActivity.this,
SecondActivity.class);
// Starts TargetActivity
startActivity(i);
11
IMPLICIT INTENTS
These intents do not name a target and the field for the
component name is left blank. Implicit intents are often
used to activate components in other applications.
Implicit intents, when you don’t know who to call.
For Example:
13
Fundamental cases for intent
• To start an activity
An activity represents a single screen in an app. You can
start a new instance of an activity by passing intent to
startActivity(). The intent describes the activity to start
and carries any necessary data.
• To start Service
A service is a component that performs operations in the
background without a user interface. You can start a
service to perform a one-time operation
( such as download file) by passing an intent to
startService(). The intent describes the activity to start
and carries any necessary data.
• To deliver a broadcast
A broadcast is a message that any app can receive. The
system delivers various broadcasts for system events.
Such as when the system boots up or the device starts
charging. You can deliver a broadcast to other app by
passing an intent to sendBroadcast(),
sendOrderedBroadcast() or
sendStickyBroadcast().
Simple UI layout & Layout
Properties
Layouts define the arrangement of views.
Android layouts are defined mostly in XML.
16
Types of Layout
❑ Linear Layout
• Used to align views horizontally or vertically.
• Use android:orientation attribute to define the
orientation.
❑ Relative Layout
• Used to arrange views in positions relative to other views or
Parent Views/layouts.
❑ Table Layout
• Used to arrange views in rows and columns
• TableRow element can be used to define rows.
• android:layout_span attributes is used to span views across
columns.
❑ Absolute Layout
Absolute Layout enables you to specify the exact
location of its Objects.
❑ Frame Layout
18
Layout Attribute
19
Linear Layout
LinearLayout is a view group that aligns all
children in a single direction, vertically or
horizontally.
20
Example
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Button" />
</LinearLayout>
21
Relative Layout
RelativeLayout allows to position the widget
relative to each other. This can be used for complex
layouts.
A simple usage for RelativeLayout is if you want to
center a single component. Just add one component
to the RelativeLayout and set
the android:layout_centerInParentattribute to true.
22
Example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/> 21
</RelativeLayout>
Grid Layout
GridLayout was introduced with Android 4.0. This
layout allows you to organize a view into a Grid.
GridLayout separates its drawing area into: rows,
columns, and cells.
You can specify how many columns you want to define
for each View, in which row and column it should be
placed as well as how many columns and rows it should
use.
If not specified, GridLayout uses defaults, e.g., one
column, one row and the position of a Viewdepends on
the order of the declaration of the Views.
24
Frame Layout
FrameLayout is a layout manager which draws
all child elements on top of each other. This
allows to create nice visual effects.
25
UI Controls in Android
List of UI controls:
TextView(Text / Labels)
EditText
Push Button
ToggleButton
ImageButton
CheckBox
RadioButton
RadioGroup
26
TextView
-It is a view which is used to display text to the
user.
EditText
28
RadioButton
RadioGroup and RadioButton :-
-The RadioButton has two states: either checked or
unchecked.
-A RadioGroup is used to group together one or more
RadioButton views, thereby allowing only one
RadioButton to be checked within the RadioGroup.
29