Professional Documents
Culture Documents
Introduction To Android
Introduction To Android
Introduction to Android
OBJECTIVES
https://www.tutorialspoint.com/android/android_overview.htm
Source: https://gs.statcounter.com/os-market-
share/mobile/worldwide/#monthly-201706-202308-bar
Android
Versions
and their names
Source: https://mfidie.com/list-of-all-android-versions-and-their-names/
• Both versions are first commercial
versions. Officially released publicly in
2008 and 2009. The first android
commercial version was placed on HTC
Android 1.0 and dream device. These versions were
released without codename.
• Android 1.0 (alpha):
1.1 (Unnamed) • Google Maps
• Camera
• Gmail, Contacts and Google
Synchronization
• Web Browser
• Wireless supports – WiFi and
Bluetooth
• Android 1.1 (beta):
• Add Save attachment in message
• Provides reviews and details when
user search business on maps
Released in April 2009. The
first released codename
with official name. It
brought features in UI
Android 1.5 design and update several
(CupCake) new features are:
▪ Screen Recording
Android 4.4 ▪ KitKat adds a feature in
‘Google now’. Its name is
(Kikat) ‘OK Google’. “OK Google”
allows access google now to
the user without touching
your mobile phone.
▪ GPS Support
▪ Offline music support
▪ UI updates for google map
navigation and alarm.
▪ Also, introduce Emoji’ to
google keyboard.
Released in November
2014. Support ART(
Android RunTime)
Android 5.0 and
5.1 (Lollipop) ▪ Save battery on some
device
▪ Improvement in UI
▪ New material design
▪ Bug fixes
▪ Multiple sim card
support
▪ High definition voice
call
Released in May 2015.
▪ Fingerprint
Android 6.0 authentication
(Marshmallow) ▪ USB Type C support
▪ Save battery-’Sleep
Mode’
▪ App permission
model-OPT(send
request for
permission)
▪ New Emoji’s
Released in August
2016. It was announced
with native split-screen
Android 7.0 mode and data saver
(Nougat) feature.
▪ Provide multitasking
▪ Providing multi-
window mode
▪ Improve in storage
manager
▪ Display touch
improvement
Released in August 2017.
There some updated new
Android 8.0 features
(Oreo)
▪ Support PIP(Picture-in-
Picture)
▪ Multi-display support
▪ Google Play support
▪ Adaptive icons
▪ Improve notification
system
Released in August 2018.
▪ A "screenshot" button
Android 9.0 has been added
▪ A new "Lockdown"
(Pie) mode for biometrics
▪ Support for display
cutouts
▪ Adaptive Batter
prediction
▪ Adaptive brightness
modifies screen
brightness based on
user habits.
Android 10
Released in September 3 2019. Known as “Queen
Cake”, internally as Quince Tart.
1. Applications
2. Android Framework
3. Android Runtime
4. Platform Libraries
5. Linux Kernel
Source: https://www.tutlane.com/tutorial/android/android-architecture
Android
Architecture
Source: https://www.tutlane.com/tutorial/android/android-architecture
Android Architecture
Linux Kernel is the main component in android to provide
its operating system functions to mobile and Dalvik Virutal
Machine (DVM) which is responsible for running a mobile
application.
Source: https://www.tutlane.com/tutorial/android/android-architecture
References
• https://google-developer-training.gitbooks.io/android-developer-fundamentals-course-
concepts/content/en/Unit%201/10_c_intro_to_android.html
• https://www.tutorialspoint.com/android/android_overview.htm
• https://www.udemy.com/learn-android-application-development-y/learn/lecture/7782698#overview
• https://www.androidauthority.com/history-android-os-name-789433/
• https://developer.android.com/about/versions
• https://mfidie.com/list-of-all-android-versions-and-their-names/#android-14
Module 2
Android Studio
OBJECTIVES
• JDK
https://www.oracle.com/technetwork/java/javase/downloads/index.html
• Android Studio
https://developer.android.com/studio/
System Requirements
https://developer.android.com/studio
Create an Android project
1. click Start a new Android Studio project Or if you have a project opened, select File > New > New
Project.
Create an Android project
2. In the Choose your project window, select Empty Activity
3. Click Next.
4. In the Configure your project window, enter the following values:
Name: "My First App"
Package name: "com.example.myfirstapp"
Check the box next to Use AndroidX artifacts
You might want to change the project location.
Leave the other options as they are.
5. If you prefer to write your app in Java, select Java from the Language drop down.
6. Click Finish.
Java or
Kotlin
Android Studio Interface
Android Studio Interface
1. The toolbar lets you carry out a wide range of actions, including running your app and
launching Android tools.
2. The navigation bar helps you navigate through your project and open files for editing. It
provides a more compact view of the structure visible in the Project window.
3. The editor window is where you create and modify code. Depending on the current file
type, the editor can change. For example, when viewing a layout file, the editor displays
the Layout Editor.
4. The tool window bar runs around the outside of the IDE window and contains the buttons
that allow you to expand or collapse individual tool windows.
5. The tool windows give you access to specific tasks like project management, search,
version control, and more. You can expand them and collapse them.
6. The status bar displays the status of your project and the IDE itself, as well as any
warnings or messages.
Running your Application
• Run on real Device
• Run on Emulator
Running your Application
• Run on real Device
o Connect your Android Phone to the computer
IDE Familiarization
References
• https://developer.android.com/training/basics/firstapp/creating-project
• https://developer.android.com/studio/intro/?gclid=EAIaIQobChMIxuSkvaqk4wIVUnZgCh131Qe3EA
AYASABEgJSz_D_BwE
Module 3
Application Components and
Resources
OBJECTIVES
2 anim/
XML files that define property animations. They are saved in res/anim/ folder and accessed from
the R.anim class.
XML files that define Tween animations. Property animations can also be saved in this directory, but
the animator/ directory is preferred for property animations to distinguish between the two types.
3 color/
XML files that define a state list of colors. They are saved in res/color/ and accessed from
the R.color class.
XML files that define a state list of colors. For more information, see Color state list resource.
Resource Organization
# Directory & Resource Type
4 drawable/
Image files like .png, .jpg, .gif or XML files that are compiled into bitmaps, state lists, shapes,
animation drawable. They are saved in res/drawable/ and accessed from the R.drawable class.
Bitmap files (PNG, .9.png, JPG, or GIF) or XML files that are compiled into the following drawable
resource subtypes:
• Bitmap files
• Nine-patches (re-sizable bitmaps)
• State lists
• Shapes
• Animation drawables
• Other drawables
For more information, see Drawable resources.
5 layout/
XML files that define a user interface layout. They are saved in res/layout/ and accessed from
the R.layout class.
XML files that define a user interface layout. For more information, see Layout resource.
Resource Organization
# Directory & Resource Type
6 menu/
XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu.
They are saved in res/menu/ and accessed from the R.menu class.
XML files that define app menus, such as an options menu, context menu, or submenu. For more
information, see Menu resource.
7 raw/
Arbitrary files to save in their raw form. You need to call Resources.openRawResource() with the
resource ID, which is R.raw.filename to open such raw files.
Arbitrary files to save in their raw form. To open these resources with a raw InputStream,
call Resources.openRawResource() with the resource ID, which is R.raw.filename.
However, if you need access to the original filenames and file hierarchy, consider saving resources
in the assets/ directory instead of res/raw/. Files in assets/ aren't given a resource ID, so you can
only read them using AssetManager.
Resource Organization
# Directory & Resource Type
8 values/
XML files that contain simple values, such as strings, integers, and colors.
Whereas XML resource files in other res/ subdirectories define a single resource based on the XML
filename, files in the values/ directory describe multiple resources. For a file in this directory, each
child of the <resources> element defines a single resource. For example, a <string> element creates
an R.string resource, and a <color> element creates an R.color resource.
Because each resource is defined with its own XML element, you can name the file whatever you
want and place different resource types in one file. However, for clarity, you might want to place
unique resource types in different files. For example, here are some filename conventions for
resources you can create in this directory:
• arrays.xml for resource arrays (Typed arrays)
• colors.xml for Color values
• dimens.xml for Dimension values
• strings.xml for String values
• styles.xml for Styles
For more information, see String resources, Style resource, and More resource types.
Resource Organization
# Directory & Resource Type
9 xml/
Arbitrary XML files that can be read at runtime by calling Resources.getXML(). Various XML
configuration files must be saved here, such as a Search configuration.
10 font/
Font files with extensions such as TTF, OTF, or TTC, or XML files that include a <font-
family> element. For more information about fonts as resources, see Add a font as an XML
resource.
Accessing Resources
• Accessing Resources in Code
When your Android application is compiled, a R class gets
generated, which contains resource IDs for all the resources
available in your res/ directory. You can use R class to
access that resource using sub-directory and resource name
or directly resource ID.
Accessing Resources
• Accessing Resources in Code
Example 1
To access res/drawable/myimage.png and set an ImageView you will use following code −
Accessing Resources
• Accessing Resources in Code
Example 2
Consider next example where res/values/strings.xml has following definition −
you can set the text on a TextView object with ID msg using a resource ID as follows −
Accessing Resources
• Accessing Resources in Code
Example 3
Consider a layout
res/layout/activity_main.xml
with the following
definition −
Accessing Resources
• Accessing Resources in Code
Example 3
This application code will load this layout for an Activity, in the onCreate() method as follows −
Accessing Resources
• Accessing Resources in XML
Consider the following resource XML res/values/strings.xml file that includes a color resource
and a string resource −
Now you can use these resources in the following layout file to set the text color and text string
as follows −
DEMONSTRATION
• https://developer.android.com/guide/topics/resources/providing-resources
Module 4
Activities
OBJECTIVES
http://tutorials.jenkov.com/android/activity.html
Activity Life Cycle Methods
All activities in your Android apps are represented by an activity class. These
activity classes are subclasses of android.app.Activity. The Activity class contains
a set of methods that corresponds to the life cycle states an activity can be in.
onCreate()
This is the first callback and called when the activity is first created.
onStart()
This callback is called when the activity becomes visible to the user.
onResume()
This is called when the user starts interacting with the application.
http://tutorials.jenkov.com/android/activity.html
Activity Life Cycle Methods
onPause()
The paused activity does not receive user input and cannot execute
any code and called when the current activity is being paused and
the previous activity is being resumed.
onStop()
This callback is called when the activity is no longer visible.
onDestroy()
This callback is called before the activity is destroyed by the system.
onRestart()
This callback is called when the activity restarts after stopping it.
http://tutorials.jenkov.com/android/activity.html
Creating an Activity
An activity is a subclass of the Android class android.app.Activity .
http://tutorials.jenkov.com/android/activity.html
Creating an Activity
All activities, should be documented on your manifest file. To do
this, add an <activity> element as a child of the <application>
element.
https://developer.android.com/guide/components/activities/intro-activities
Creating an Activity
An activity class loads all the UI component using the XML file available
in res/layout folder of the project during the onCreate() callback.
Following statement loads UI components from
res/layout/activity_main.xml file:
http://tutorials.jenkov.com/android/activity.html
DEMONSTRATION
Source: https://developer.android.com/guide/topics/ui/declaring-layout
Layouts
• Each layout file must contain exactly one root element, which must
be a View or ViewGroup object.
• Once you've defined the root element, you can add additional layout
objects or widgets as child elements
• to gradually build a View hierarchy that defines your layout.
Source: https://developer.android.com/guide/topics/ui/declaring-layout
Layouts
• View objects are usually called "widgets" and can be one of many
subclasses, such as Button or TextView.
• ViewGroup objects are usually called "layouts" can be one of many
types that provide a different layout structure, such as LinearLayout
or ConstraintLayout .
• View and ViewGroup can be declared in two ways:
• Declare UI Elements in XML
• Instantiate Layout Elements at Runtime
Source: https://developer.android.com/guide/topics/ui/declaring-layout
Declare UI elements in XML
Create your layout in xml
Source: https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Instantiate Layout Elements at Runtime
Source: https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Layout Resource
A layout resource defines the architecture for the UI in an Activity or a component of a UI.
file location:
res/layout/filename.xml
The filename will be used as the resource ID.
compiled resource datatype:
Resource pointer to a View (or subclass) resource.
resource reference:
In Java: R.layout.filename
In XML: @[package:]layout/filename
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – syntax
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
<ViewGroup>
• A container for other View elements.
LinearLayout, RelativeLayout, and FrameLayout.
• Do not assume that any derivation of ViewGroup will accept nested Views.
• Some ViewGroups are implementations of the AdapterView class, which
determines its children only from an Adapter.
• attributes
android:id
android:layout_height
android:layout_width
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
<View>
• An individual UI component, generally referred to as a "widget". Different kinds
of View objects include TextView, Button, and CheckBox.
• attributes
android:id
android:layout_height
android:layout_width
More attributes are supported by the View base class, and many more are supported by each
implementation of View.
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
android:id
Resource ID. A unique resource name for the element, which you can use to
obtain a reference to the View or ViewGroup from your application.
There many other ID resources that are offered by the Android framework.
When referencing an Android resource ID, android:id="@id/resource_id"
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
android:layout_height and android:layout_width
Dimension or keyword. Required. The height and width for the group
The height and width value can be expressed using any of the dimension units
supported by Android (px, dp, sp, pt, in, mm) or
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – elements
Custom View elements
You can create your own custom View and ViewGroup elements and
apply them to your layout the same as a standard layout element. You
can also specify the attributes supported in the XML element. To learn
more, see the https://developer.android.com/guide/topics/ui/custom-
components.html
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Resource – example
XML file saved at res/layout/main_activity.xml:
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Loading View
1. Define a view/widget in the layout file and assign it a unique ID:
2. Then create an instance of the view object and capture it from the
layout (typically in the onCreate() method)
Source: https://developer.android.com/guide/topics/resources/layout-resource.html
Layout Attributes
Some of common layout attributes used in android application.
Source:https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Layout Types
• Linear Layout
• Relative Layout
• Frame Layout
• Table Layout
• Web View
• List View
• Grid View
Source:https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-gridview-webview
Linear Layout
LinearLayout is a ViewGroup subclass which is used to render all child View instances one by one
either in Horizontaldirection or Vertical direction based on the orientation property.
In android, we can specify the linear layout orientation using android:orientation attribute.
Source: https://www.tutlane.com/tutorial/android/android-linearlayout-with-examples
Linear Layout
Source: https://www.tutlane.com/tutorial/android/android-linearlayout-with-examples
Linear Layout
Source: https://www.tutlane.com/tutorial/android/android-linearlayout-with-examples
Relative Layout
It is a ViewGroup which is used to specify the position of
child View instances relative to each other (Child A to the
left of Child B) or relative to the parent (Aligned to the
top of parent).
Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Relative Layout
Following are the some of most useful layout properties available to views in RelativeLayout.
Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Relative Layout
Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Relative Layout
Source: https://www.tutlane.com/tutorial/android/android-relativelayout-with-
examples
Frame Layout
Framelayout is a ViewGroup subclass which is used to
specify the position of View instances it contains on the
top of each other to display only single View inside the
FrameLayout.
Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Frame Layout
Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Frame Layout
Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Table Layout
TableLayout is a ViewGroup subclass which is used to
display the child View elements in rows and columns.
Source: https://www.tutlane.com/tutorial/android/android-tablelayout-with-examples
Table Layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
</TableRow>
</TableLayout>
Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Table Layout
Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
Table Layout
Source: https://www.tutlane.com/tutorial/android/android-framelayout-with-examples
WebView Layout
WebView is an extension of View class and it is used to
show the static HTML web pages content or remote web
pages content with URL in android applications as a part
of our activity layout.
Source: https://www.tutlane.com/tutorial/android/android-webview-with-examples
WebView Layout
XML
Java
Source: https://www.tutlane.com/tutorial/android/android-webview-with-examples
WebView Layout
Source: https://www.tutlane.com/tutorial/android/android-webview-with-examples
ListView Layout
ListView is a ViewGroup which is used to display the list
of scrollable of items in multiple rows and the list items
are automatically inserted to the list using an adapter.
Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout
Generally, in android we have a different types of adapters available to fetch the data from different data
sources to fill the data into adapter views, those are
Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout
Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout
Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
ListView Layout
Source: https://www.tutlane.com/tutorial/android/android-listview-with-examples
GridView Layout
Grid View is a ViewGroup which is used to display items
in a two dimensional, scrollable grid and grid items are
automatically inserted to the gridview layout using a list
adapter.
Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout
Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout
ImageAdapter.java
Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout
Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
GridView Layout
Source: https://www.tutlane.com/tutorial/android/android-gridview-with-examples
< Controls >
Controls
Input controls are the interactive components in your app's user interface.
Android provides a wide variety of controls you can use in your UI, such as
buttons, text fields, seek bars, check box, zoom buttons, toggle buttons,
and many more.
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Controls
A View is an object that draws something on the screen that the user can interact with
and a ViewGroup is an object that holds other View (and ViewGroup) objects in order to
define the layout of the user interface.
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Controls
There are number of UI controls provided by Android that allow you to build the
graphical user interface for your app.
TextView This control is used to display text to the user.
EditText A predefined subclass of TextView that includes rich editing
capabilities.
AutoCompleteTextView A view that is similar to EditText, except that it shows a list of
completion suggestions
ButtonA A push-button that can be pressed, or clicked, by the user to
perform an action.
ImageButtonAn An AbsoluteLayout which enables you to specify the exact location
of its children. This shows a button with an image (instead of text)
that can be pressed or clicked by the user
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Controls
CheckBox An on/off switch that can be toggled by the user. You should use
check box when presenting users with a group of selectable
options that are not mutually exclusive.
ToggleButton An on/off button with a light indicator.
RadioButton The RadioButton has two states: either checked or unchecked.
RadioGroup A RadioGroup is used to group together one or more RadioButtons.
ProgressBar The ProgressBar view provides visual feedback about some
ongoing tasks, such as when you are performing a task in the
background.
Spinner A drop-down list that allows users to select one value from a set.
TimePicker The TimePicker view enables users to select a time of the day, in
either 24-hour mode or AM/PM mode.
DatePicker The DatePicker view enables users to select a date of the day.
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Creating Controls
A view object may have a unique ID assigned to it which will identify the View uniquely
within the tree.
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
Creating Controls
Create an instance of the Control object and capture it from the layout in your Java
activity file
Source: https://www.tutorialspoint.com/android/android_user_interface_controls.htm
DEMONSTRATION
Source: https://developer.android.com/guide/topics/ui/ui-events#java
Event Implementation
Implement OnClickListener as a part of your Activity. This will avoid the extra class load and object
allocation.
Source: https://developer.android.com/guide/topics/ui/ui-events#java
DEMONSTRATION
Event Handling
References
• https://www.tutlane.com/tutorial/android/android-ui-layouts-linear-relative-frame-table-listview-
gridview-webview
• https://www.tutorialspoint.com/android/android_user_interface_layouts.htm
• https://www.tutlane.com/tutorial/android/android-ui-controls-textview-edittext-radio-button-checkbox
• https://www.tutorialspoint.com/android/android_user_interface_controls.htm