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

Ap Unit-2

The document discusses Android activities and GUI design concepts. It covers hardware design considerations for mobile devices like lower processing power, limited RAM and storage. It describes how Android applications should be fast, efficient and use minimal storage. It defines activities as single screens with a user interface and discusses the activity lifecycle. It also covers creating activities through the manifest file, programmatically or using menus and describes using intents to navigate between application components.

Uploaded by

storianmarketing
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)
34 views

Ap Unit-2

The document discusses Android activities and GUI design concepts. It covers hardware design considerations for mobile devices like lower processing power, limited RAM and storage. It describes how Android applications should be fast, efficient and use minimal storage. It defines activities as single screens with a user interface and discusses the activity lifecycle. It also covers creating activities through the manifest file, programmatically or using menus and describes using intents to navigate between application components.

Uploaded by

storianmarketing
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
You are on page 1/ 29

UNIT:2

Android activities & GUI


design concepts

1
DESIGN CRITERIA FOR
ANDROID APPLICATION
 Hardware Design Consideration
 Compared to desktop or laptop computers, mobile
devices have relatively:
 Low processing power

 Limited RAM

 Limited Permanent storage capacity

 Small screens with low resolution

2
DESIGN DEMANDS FOR ANDROID
APPLICATION

 While developing an android Application for


mobile devices we need to consider following
design demands in mind:
 It should be fast & efficient.

 It should use less storage as possible

 It should present consistent UI for all devices.

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

 onStart(): Called when the activity becomes


visible to the user
 onResume(): Called when the
activity starts interacting with the user
 onPause(): Called when the current
activity is being paused and the previous
activity is being resumed

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

 When we create a simple Android Application the


first Activity will be Automatically created.
 An Activity can be created using three different
ways.
 Through AndroidManifest.xml file

 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:

// Implicit Intent by specifying a URL


Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
// Starts Implicit Activity
startActivity(i);

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.

 Various properties of Layouts can be set using XML


attributes.

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

The FrameLayout is a placeholder on screen that you


can use to display a single view.
❑ GridView

GridView is a ViewGroup that displays items in a


two-dimensional, scrollable grid

18
Layout Attribute

 Each layout has a set of attributes which define the


visual properties of that layout. There are few common
attributes among all the layouts and their are other
attributes which are specific to that layout. Following
are common attributes and will be applied to all the
layouts:

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

-A subclass of the TextView view that allows users


to edit its text content
 Button(push button)

-It is a push-button that can be pressed, or clicked,


by the user to perform an action.
 Toggle button

-It is an on/off button with a light indicator.


-It displays checked/unchecked states using a light
indicator. 25
 Image Button
-It is similar to the Button view, except that it also
displays an image
 Checkbox

-A special type of button that has two states: checked


or unchecked
-You should use checkboxes when presenting users
with a group of selectable options that are not
mutually exclusive.

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

You might also like