MCAD - Unit 3
MCAD - Unit 3
06/03/2023
2 DESIGN CRITERIA FOR ANDROID
APPLICATION
Hardware Design Consideration
Compared to desktop or laptop computers, mobile devices have relatively:
1. Low processing power
2. Limited RAM
3. Limited Permanent storage capacity
4. Small screens with low resolution
5. Limited Battery Life
06/03/2023
3 DESIGN DEMANDS FOR ANDROID
APPLICATION
While developing an android Application for mobile devices we need to consider
following design demands in mind:
1. It should be fast & efficient.
2. It should use less storage as possible
3. It should present consistent UI for all devices.
06/03/2023
4 Activity & Activity Life Cycle
06/03/2023
5 Activity Life Cycle
06/03/2023
6 Activity Life Cycle Methods
Method Description
This method is called when the activity becomes visible to the user. It is
onStart() used to initialize any components that need to be started when the activity
is visible.
This method is called when the activity is in the foreground and has the
onResume() user focus. It is used to start or resume any actions that were paused in the
onPause() method.
06/03/2023
7 Activity Life Cycle Methods
Method Description
This method is called when the activity loses the user focus and becomes
onPause() partially visible. It is used to pause any ongoing actions or release resources
that are not needed when the activity is not in the foreground.
This method is called when the activity is no longer visible to the user. It is
onStop() used to release any resources that are not needed when the activity is not
visible.
This method is called when the activity is being destroyed. It is used to
onDestroy()
release any resources that were allocated during the activity's life cycle.
This method is called when the activity after the activity has been stopped
onRestart() but before it is started again. It is called when the user navigates back to the
activity from the stopped state.
06/03/2023
Android project framework
8
AndroidManifest.xml: This file contains essential information about the application, such
as its package name, version, permissions, and activities. In Eclipse, this file is located in
the project's root directory.
Java source code: This is the code that provides the logic and functionality for the
application. In Eclipse, the Java source code is located in the /src directory of the project.
Resources: Resources include all the non-code assets used by the application, such as
layouts, images, strings, and other resources. In Eclipse, these resources are stored in the
/res directory of the project.
Project properties: The project properties contain the project's settings, such as the build
target, Java compiler, and other project-specific settings. In Eclipse, these properties can be
accessed by selecting "Project" > "Properties" from the menu bar.
Libraries: Libraries are pre-built code modules that can be included in the application to
provide additional functionality. In Eclipse, libraries can be added to the project by
selecting "Project" > "Properties" > "Java Build Path" from the menu bar.
06/03/2023
Intent and its type
9
06/03/2023
Intent and its type
10
putExtra() method is used to add data to an Intent object before it is passed to another
component. It takes two arguments: a key and a value. The key is a string that identifies the data
being passed, and the value is the actual data being passed.
getExtras() is a method in the Android Intent class that is used to retrieve all of the extras that
were added to an Intent object using the putExtra() method. The extras are returned as a Bundle
object, which is a collection of key-value pairs.
06/03/2023
Intent and its type
11
2. Implicit Intent: An implicit Intent is used to request an action from another application, or to perform
an action that does not require a specific component. It is typically used to start an activity that can
handle a certain type of data, such as opening a web page or sending an email.
Code:
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(intent);
There are also several predefined actions and categories that can be used with Intents, such as
ACTION_VIEW, ACTION_SEND that can be used to specify the type of action that is being
requested, and the type of data that is being passed between components.
06/03/2023
12 Different Layouts in Android-FrameLayout
In Android, FrameLayout is a ViewGroup subclass that is used to specify a single view
that fills the entire layout container.
It is generally used to hold a single child view, such as a single image, icon or button.
Some of the important attributes of FrameLayout in Android are:
layout_width and layout_height: These attributes are used to specify the width and height
of the FrameLayout, either in pixels or as a dimension or a fraction of the parent view.
gravity: This attribute is used to specify the gravity of the child view within the
FrameLayout. For example, setting gravity="center" will center the child view horizontally
and vertically within the FrameLayout.
foreground: This attribute is used to specify a drawable or color that should be drawn in
front of the child view. This can be used to add a border or highlight to the child view.
background: This attribute is used to specify a drawable or color that should be used as the
background of the FrameLayout.
06/03/2023
13 Different Layouts in Android Linear Layout
Android LinearLayout is a view group that aligns all children in
either vertically or horizontally.
06/03/2023
14 Different Layouts in Android Linear Layout
android:id: This is the ID which uniquely identifies the layout.
android:gravity: This specifies how an object should position its content, on both the X and
Y axes. Possible values are top, bottom, left, right, center, center_vertical,
center_horizontal etc.
android:orientation: This specifies the direction of arrangement and you will use
"horizontal" for a row, "vertical" for a column. The default is horizontal.
06/03/2023
15 Different Layouts in Android-Relative Layout
Relative layout is a type of layout used in Android app development that allows you to
position and align views relative to other views or the parent layout. It is useful when you
want to create a more flexible layout that can adapt to different screen sizes and
orientations.
06/03/2023
16 Different Layouts in Android-Relative Layout
06/03/2023
17 Different Layouts in Android-Relative Layout
06/03/2023
19 Different Layouts in Android-Table Layout
1 android:id
This is the ID which uniquely identifies the layout.
2 android:collapseColumns
This specifies the zero-based index of the columns to collapse. The column indices
must be separated by a comma: 1, 2, 5.
3 android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be separated
by a comma: 1, 2, 5.
4 android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be
separated by a comma: 1, 2, 5
06/03/2023
20 Different Layouts in Android-Absolute Layout
An Absolute Layout is used to specify exact locations (x/y coordinates) of its children.
Absolute layouts are less flexible and harder to maintain than other types of layouts without
absolute positioning.
06/03/2023
21 Different Layouts in Android-Absolute Layout
1 android:id
This is the ID which uniquely identifies the layout.
2 android:layout_x
This specifies the x-coordinate of the view.
3 android:layout_y
This specifies the y-coordinate of the view.
06/03/2023
22 Different Layouts in Android-List View
Android ListView is a view which groups several items and display them in vertical scrollable
list. The list items are automatically inserted to the list using an Adapter that pulls content
from a source such as an array or database.
An adapter actually bridges between UI components and the data source that fill data into UI
Component. Adapter holds the data and send the data to adapter view, the view can takes the
data from adapter view and shows the data on different views like as spinner, list view, grid
view etc.
06/03/2023
23 Different Layouts in Android-List View
Sr.No Attribute & Description
1 android:id
This is the ID which uniquely identifies the layout.
2 android:divider
This is drawable or color to draw between list items.
3 android:dividerHeight
This specifies height of the divider. This could be in px, dp, sp, in, or mm.
4 android:entries
Specifies the reference to an array resource that will populate the ListView.
5 android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each footer
view. The default value is true.
6 android:headerDividersEnabled
When set to false, the ListView will not draw the divider after each header
view. The default value is true.
06/03/2023
24 List of UI Controls
Button - This control is used to create a clickable button that performs an action when pressed.
TextView - This control is used to display text on the screen, such as labels or instructions.
EditText - This control is used to accept user input, such as text or numbers.
ImageView - This control is used to display images on the screen.
RadioButton - This control is used to create a group of mutually exclusive options that the user
can select from.
CheckBox - This control is used to create a group of options that the user can select multiple
items from.
06/03/2023
25 Button
< Button android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
android:onClick="onButtonClick" />
In Java file :
public void onButtonClick(View view) {
// Perform some action when the button is clicked
}
06/03/2023
26 TextView
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!" />
In Java file :
06/03/2023
27 EditText
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />
In Java file :
06/03/2023
28 CheckBox
<CheckBox
android:id="@+id/myCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to the terms and conditions" />
In Java file :
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
06/03/2023
30 RadioButton
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
</RadioGroup>
In Java File:
RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);
RadioButton radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
RadioButton radioButton2 = (RadioButton) findViewById(R.id.radioButton2);
06/03/2023
31 ToggleButton
<ToggleButton
android:id="@+id/myToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Off"
android:textOn="On" />
In Java File:
ToggleButton myToggleButton = (ToggleButton) findViewById(R.id.myToggleButton);
06/03/2023
32 ImageButton
<ImageButton
android:id="@+id/myImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image" />
In Java File:
ImageButton myImageButton = (ImageButton) findViewById(R.id.myImageButton);
myImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Perform some action when the ImageButton is clicked
}
}); 06/03/2023
33 R.Java File
The R.java file is an auto-generated class in Android that contains constants used to reference
resources such as layouts, strings, images, and other assets in an Android application.
It's an important file in an Android project as it enables developers to reference resources in their
code using simple and readable names, rather than using resource IDs directly.
Here are some of the reasons why the R.java file is important in Android:
1. Accessing resources: The R.java file provides a simple way to reference resources used in an Android
application.
2. Organizing resources: The R.java file organizes resources by type and name, making it easy for
developers to find and reference the resources they need.
3. Auto-generated: The R.java file is auto-generated by the Android build system, so developers don't have
to create it manually.
4. Error checking: The R.java file is checked by the Android build system for errors, such as missing
resources or duplicate resource IDs.
06/03/2023
34 Padding, Margin, Weightsum
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal“
android:padding="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:weightSum="3">
06/03/2023
35 Padding, Margin, Weightsum
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Left Text" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Right Text" />
</LinearLayout>
06/03/2023
36 Padding, Margin, Weightsum
In this example, we have a horizontal LinearLayout that contains two TextView elements.
The LinearLayout has a padding of 16dp on all sides, and a margin of 8dp on the top and
bottom.
Note that padding adds extra space inside the view, while margin adds extra space outside
the view. weightsum specifies the total weight of the child views, and is used to calculate
their relative sizes.
The first TextView has a weight of 1, which means it will take up one-third of the available
horizontal space within the LinearLayout. The second TextView has a weight of 2, which
means it will take up two-thirds of the available horizontal space.
06/03/2023
GTU Questions
37
06/03/2023
GTU Questions
38
06/03/2023
GTU Questions
39
06/03/2023