MOBILE APPLICATION DEVELOPMENT USING
ANDROID
Unit– I
Introducing Android:
Android Inc was founded in Palo Altoof California, US by Andy Rubin,
Rich Miner, Nick Scars ant Chris White during 2003. After that it was acquired
by Google in 2005.
What is Android?
1. Android is a stack of software for mobile devices that are an Operating
System, Middleware and Key Applications.
Operating
System
Middleware
Key
Application
Fig.1.1Android Operating System
2. Android is a Linux –based operating system which is designed for touch
screen mobile devices like smart phones, tablet, computers, wrist watch and
LED-LCD android TV’s.
3. It is an open source technology that allows the software to be freely modified
and distributed by device manufacturers, wireless carriers and developers.
4. Android is written in C, C++ and JAVA Programming Languages java lies at
the top of its all development layers and therefore its applications are
primarily written in JAVA.
5. Android was invented during 2007 along with the founding of the Open
Hand set Alliance (OHA).
Fig.1.2Android Logo
What is “Open Handset Alliance”(OHA)?
Open Handset Alliance (OHA) was formed in November 2007. The OHA is the
group that is in charge of the Android smart phones operating system. It was
created by Google. The Open Handset Alliance(OHA) is a business alliance that
consists of 47 companies for developing open standard platform for mobile
devices. The members of OHA include handset manufactures, chip makers,
commercialization companies, software companies and mobile operators.
Handset
Manufactures
Mobile Operators Chip Makers
Open Handset Alliance
( OHA )
Commercialization
Software
Companies
companies
Fig.1.3 Android Open Handset Alliance
Android Ecosystem:
For Android and develop Android Applications, it is very
important to understand the Entire ecosystem of Android and the
stakeholders of this ecosystem :
Google Original
Consumers Equipment
Manufacturer
Android
Application
Freelancers Development
Centers
Fig.1.4Android Ecosystem
The stakeholders are the Consumers that own Android Devices. But there are
others as well:
Google: It develops Android.
OEMs(Original Equipment Manufactures):They manufacture
the hardware and as well the custom applications computers. Example:
LG, Sony, HTC, Samsung, etc.
Application Development Companies : They are the major
contributors to the echo
systemandemployAndroiddevelopers,andalsocontractouttheproductdevelop
ment to services companies. Example : WhatsApp, Facebook, Angry Birds
Gaming App, etc.
Freelance Android Developers: Developers have the skill set to
development they are to create their own application and published them on
to Google play store, freelancers can also generates money by developing
applications for product companies.
HISTORY OF ANDROID
The history of Android is a fascinating journey that spans several
decades, characterized by innovation, collaboration, and evolution. From its
humble beginnings, when it was competing with Nokia’s mobile OS Symbian,
the Windows Phone OS, and Blackberry OS, to its dominant position in the
mobile operating system market, Android has significantly influenced how we
interact with technology.
Here’s an in-depth look at the history of Android:
1. Early origins and development (2003-2007)
The story of Android began in 2003 when Andy Rubin, Rich Miner, Nick Sears,
and Chris White founded Android Inc. in Palo Alto, California. Their initial
goal was to develop an advanced operating system for digital cameras.
However, recognizing the potential of their project, they shifted their focus to
creating an operating system for mobile devices.
2. Acquisition by Google (2005)
In 2005, Google, led by then-CEO Eric Schmidt, acquired Android Inc., laying
the groundwork for what would become one of the most significant
developments in the mobile industry. Google’s acquisition of Android signaled
its entry into the rapidly growing smartphone market and set the stage for
developing a new mobile operating system.
3. Open Handset Alliance and the launch of Android (2007)
On November 5, 2007, the Open Handset Alliance (OHA) was unveiled. It
comprised several prominent technology companies, including Google, HTC,
Samsung, Motorola, and others. The OHA aimed to develop open standards for
mobile devices and promote innovation in the mobile industry. Shortly after, on
November 5, 2007, Google announced the first beta version of the Android
operating system.
4. Android 1.0 and the first Android device (2008)
The first commercial version of Android, Android 1.0, was released on
September 23, 2008. The HTC Dream, also known as T-Mobile G1, was the
first smart phone to run on the Android operating system. The HTC Dream
featured a touch screen interface, a physical keyboard, and access to Google
services such as Gmail, Maps, and YouTube.
Since its initial release, Android has undergone significant evolution with
regular updates and new versions introduced to the market, as we will discuss
later. The developer preview of Android 15 has been launched in 2024.
5. Growth and dominance in the mobile market
Over the years, Android has experienced tremendous growth, rapidly becoming
the world’s most popular mobile operating system. According to Statcounter, as
of January 2022, Android holds over 72% of the global mobile operating system
market share, far surpassing its competitors.
Android Versions
Android has evolved through various versions since its inception. Each version
brings new features, enhancements, and optimizations to the platform. Here is a
list of the major Android versions released to date:
Android 1.0 (Astro): The initial version of Android was released on
September 23, 2008. It introduced basic functionalities such as web browsing,
camera support, and access to Google services like Gmail and Google Maps.
Android 1.1 (Bender): Released on February 9, 2009, Android 1.1
included minor updates and bug fixes to improve system stability and
performance.
Android 1.5 (Cupcake): Introduced on April 27, 2009, Android 1.5
brought significant improvements, such as an on-screen keyboard, support for
third-party widgets, and video recording capabilities.
Android 1.6 (Donut): Released on September 15, 2009, Android 1.6
featured updates to the user interface, improved search functionality, and
support for CDMA networks.
Android 2.0/2.1 (Eclair): Android 2.0 and 2.1, known collectively as
Eclair, were released on October 26, 2009. Eclair introduced features such as
multiple account support, Bluetooth 2.1, and an updated web browser.
Android 2.2 (Froyo): Released on May 20, 2010, Android 2.2 (Froyo)
introduced significant performance improvements, support for Adobe Flash
Player, and the ability to install apps on external storage.
Android 2.3 (Gingerbread): Introduced on December 6, 2010, Android
2.3 (Gingerbread) focused on refining the user interface, improving gaming
performance, and adding support for near field communication (NFC).
Android 3.0/3.1/3.2 (Honeycomb): Android 3.0 (Honeycomb) was
released on February 22, 2011, and was specifically designed for tablets. It
featured a redesigned user interface, support for multi core processors, and
improved multitasking capabilities.
Android 4.0 (Ice Cream Sandwich): Released on October 18, 2011,
Android 4.0 (Ice Cream Sandwich) merged the tablet and smart phone versions
of Android. It introduced features such as a new user interface, enhanced
multitasking, and support for facial recognition.
Android 4.1/4.2/4.3 (Jelly Bean): Android 4.1 (Jelly Bean) was released
on July 9, 2012, followed by subsequent updates 4.2 and 4.3. Jelly Bean
introduced features such as improved performance, enhanced notifications, and
support for multiple user accounts on tablets.
Android 4.4 (KitKat): Released on October 31, 2013, Android 4.4
(KitKat) focused on optimizing the operating system for low-end devices. It
introduced features such as improved memory management, a new dialer app,
and support for cloud printing.
Android 5.0/5.1 (Lollipop): Android 5.0 (Lollipop) was released on
November 12, 2014, followed by updates to 5.1. Lollipop introduced the
Material Design language, improved performance, enhanced security features,
and support for 64-bit processors.
Android 6.0 (Marshmallow): Released on October 5, 2015, Android 6.0
(Marshmallow) introduced features such as app permissions, Google Now on
Tap, and a new battery-saving feature called Doze.
Android 7.0/7.1 (Nougat): Android 7.0 (Nougat) was released on August
22, 2016, followed by updates to 7.1. Nougat introduced features such as split-
screen multitasking, enhanced notifications, and support for Daydream VR.
Android 8.0/8.1 (Oreo): Android 8.0 (Oreo) was released on August 21,
2017, followed by updates to 8.1. Oreo introduced features, such as picture-in-
picture mode, notification dots, and improved battery life, through background
app limitations.
Android 9 (Pie): Released on August 6, 2018, Android 9 (Pie)
introduced features such as gesture-based navigation, adaptive battery, and
digital wellbeing tools to help users monitor their smartphone usage.
Android 10: Released on September 3, 2019, Android 10 introduced
features such as a system-wide dark mode, improved privacy controls, and
support for foldable smartphones.
Android 11: Released on September 8, 2020, Android 11 focused on
enhancing communication, privacy, and control with features like chat bubbles,
one-time permissions, and improved media controls.
Android 12: Released on October 4, 2021, Android 12 introduced a
major visual overhaul with Material You design language, enhanced privacy
features, and performance improvements.
Android 13: Android 13 focused on user privacy with features like a
photo picker and notification permission settings. Building on Android 12’s
tablet optimizations, Android 13 enhances system UI, multitasking, and
compatibility modes.
Android 14: Released on October 4, 2023, Android 14 enhances
accessibility with features like 200% font scaling and customizable lock
screens. Additionally, it introduces support for lossless audio formats and an
improved magnifier for low-vision users.
Android 15: It is the upcoming iteration of the Android operating
system, slated for release in early 2025. It introduces advanced encryption
features for secure data storage and transmission, among other features.
PROS OF ANDROID
The key advantages of Android are as follows:
Open source: Android is built on an open-source platform, allowing
developers to customize and modify the operating system according to their
needs. This fosters innovation and flexibility within the Android ecosystem.
Customization: Android offers extensive customization options for
users, including personalized home screens, themes, widgets, and third-party
launchers. Users can tailor their Android devices to match their preferences and
style.
Diverse hardware options: Android is available on a wide range of
devices manufactured by various companies, offering users a diverse selection
of smartphones, tablets, and other devices with different specifications, features,
and price points.
App ecosystem: The Google Play Store, Android’s official app
marketplace, offers a vast catalog of apps, games, utilities, and entertainment
content. With millions of apps available for download, users can find
applications for almost any purpose or interest.
Affordability: Android devices are available at a wide range of price
points, including budget-friendly options, making them accessible to users with
different budgets and preferences.
Disadvantages of Android
Fragmentation: Android fragmentation refers to the diversity of devices
running different Android operating system versions and customized user
interfaces (UIs) by manufacturers. This can lead to compatibility issues,
inconsistent user experiences, and delays in software updates.
Bloatware and pre-installed apps: Some Android devices come pre-
installed with bloatware, unnecessary apps, and manufacturer-specific software
that cannot be easily removed. This can consume storage space, affect
performance, and clutter the user interface.
Lack of timely updates: Android devices may not receive timely
software updates, especially for older or lower-end devices. This can leave
devices vulnerable to security threats and limit access to new features and
improvements introduced in newer Android versions
Features of Android:
Android, the mobile operating system developed by Google, offers a wide range
of features that have evolved over time. Here are some of the key features of
Android :
1. User Interface Customization: Android provides extensive options for
customizing the user interface, including widgets, wallpapers, themes, and icon
packs.
2. Multitasking : Users can easily switch between multiple apps and
perform tasks
simultaneouslyusingAndroid'smultitaskingcapabilities,suchassplit-
screenmodeand picture-in-picture mode.
3. Notifications : Android delivers rich and interactive notifications,
allowing users to
quicklyviewandrespondtomessages,emails,andalertswithoutopeningtherespectiv
e apps.
4. Google Assistant: Google's virtual assistant, Google Assistant, is deeply
integrated into Android, providing voice-controlled access to various functions,
information, and services.
5. Google Play Store : Android users have access to a vast ecosystem of
apps, games, movies, books ,and music through the Google Play Store, which
serves as the primary marketplace for downloading and purchasing digital
content.
6. Security: Android offers various security features, including built-in
malware protection, app sandboxing, secure boot process, and regular security
updates provided by Google.
7. Customizability: Android is highly customizable, allowing users to
install custom ROMs, modify system settings, and personalize their devices
according to their preferences.
8. Integration with Google Services: Android seamlessly integrates with
various Google services, such as Gmail, Google Maps, Google Drive, and
Google Photos, providing a cohesive ecosystem for users.
9. Cloud Storage: Android devices often come with built-in support for
cloud storage services, enabling users to backup their data, sync files across
devices, and access their content from anywhere.
10. Accessibility: Android offers a wide range of accessibility features,
including screen readers, magnification gestures, captioning, and voice
commands, to make the platform more inclusive for users with disabilities.
11. Device Compatibility: Android runs on a diverse range of devices,
including smart phones, tablets, smart watches, smart TVs, and automotive
systems, catering to various form factors and use cases.
12. Open Source: Android is based on the Linux kernel and is open source,
allowing developers to modify the source code, create custom distributions
(forks), and contribute to the platform's development
The Android Platform
Understanding the Android Software Stack
Android Application Architecture
The architecture of an Android system consists of a software stack of
different layers. Each layer contains group of various program components.
The software stack of architecture works in a way that each layer provides
services to the layer just above it. Together, it includes OS, middleware, and
applications. Putting all layers together comprises and architecture called
Android Architecture.
Applications
Home Contacts Phone Browser Browser
Application Framework
Activity Window Content View
Manager Manager Providers System
Package Telephony Resource Location Notification
Manager Manager Manager Manager Manager
Libraries Android Runtime
Surface Manager SSL SGL SQLite Core Libraries
Media Component Web Kit OpenGL
Dalvik Virtual Machine
Linux Kernel
Brinder(IPS)
Display Driver Camera Driver Flash Memory Driver
Driver
Power
Keypad Driver WiFi Driver Audio Drivers
Management
Fig.1.5AndroidArchitecture
Android Architecture as a following layers are:-
1. Application Layer
2. Application Framework Layer
3. Android Runtime
4. Libraries
5. Linux Kernal
As the Android Architecture is a software stack of different layers. Let’s
discuss the each layer one-by-one.
5.Linux Kernal : Linux Kernal is the root layer in the android
architecture. The interaction of the hardware into software is provided by
means of Linux. All the hardware devices are handled by this Kernal.
Drivers are the small program written specifically to communicate with the
hardware.
It has all the major hardware drivers a 000s display driver, camera driver,
power management driver, and so forth.
For example, the Linux kernel has camera driver. On installing the Android
OS in a compatible device, the Linux kernel will search the camera at hen
make it available to the system by using camera driver.
The Linux kernel not only contains hardware drivers, but also serves as the
abstraction layer for other layers Since the core of the Android system lies in
the Linux kernel, all the main functionality of the system is based of Linux.
The foundation of Android is Linux, which is a much powerful system;
therefore, it provides a great versatility to the Android OS to work it on
multiple devices without any (or few) glitches.
4. Libraries Layer: The layer next to the Linux kernel layer is the
Android's native libraries. This layer provides the device, which has the
capability to handle different types of data and information. These libraries
are coded in C and C++ languages for fast procedural transactions of data. A
brief description of some of the native Android libraries is as follows :
Media library provides support to play and record an audio and video
formats.
Surface manager responsible for managing access to the display
subsystem.
SGL and OpenGL both cross- language, cross-platform application
program interface (API) are used for 2D and 3D computer graphics.
SQLite provides database support and Free Type provides font support.
Web-Kit: This open source web browser engine provides all the
functionality to display web content and to simplify page loading.
SSL(SecureSocketsLayer)issecuritytechnologytoestablishanen
cryptedlink between a web server and a web browser.
3. Android Runtime: Consist of Core Libraries and Dalvik Virtual
Machine.
a. Dalvik Virtual Machine(DVM):The Dalvik Virtual
Machine(DVM)is an android virtual machine optimizes for mobile
devices. It optimized the virtual machine for memory, battery life and
performance.
Dalvik is a name of town in Iland. The Dalvik VM was written by “Dan
Bornstein”.
Optimizing the Virtual Machine for memory, battery life, and
performance.
Conversion of class files in to .dex file through Dex compiler that runs on
Dalvik VM.
Converting multiple class files into dex files.
The Dex compiler helps convert the class file into .dexfile, the following
image shows how it flows:
First of all the .java file converts into .class file with the help of Java
compiler.
Next .class file converts into .dex file using Dec compiler.
Then finally the packaging process is handled by the Android Assets
packaging(aapt) tools.
b. Core Libraries:
The core libraries enable android developers to write android application
using standard java programming language.
Core Java Libraries are the exclusively design java libraries for android
rather than java SE (Standard Edition) and java ME (Mobile Edition).
However most of the functionality of this libraries similar to the SE libraries.
This libraries consist of data structure, file access, network access, utilities and
Graphics.
2. Android Runtime:
Application frame work is of utmost importance for developer as the blocks
inside this layer directly communicate with Android applications.
The basic and much needed functionalities such as resource management and
voice call management are provided by this layer.
From the developer's perspective, this layer provides basic building blocks
for Android applications. The important blocks of Application framework
are as follows
Activity Manager- Manages the activity life cycle of applications.
Content Providers- Provided at a sharing between applications.
Telephony Manager - Manages all voice calls. This management can
be considered as optional. If your application is meant to use the voice calls,
then telephony manager is used.
Location Manager- Manages the activities related with location in your
application.
Resource Manager- Manages the different kinds of resources in an
application.
1. Application Layer:
Application layer is the top layer in the Android architecture. This is the place
where our application is finally deployed over a device. Some applications are
installed by default in a device, such as SMS client app, dialer, Web browser,
and contact manager.
Pre-installed applications can be replaced by newly developed applications.
This is the fact which makes Android OS so flexible. Many device vendors
modify the pure Android applications with their own applications for the sake
of different feel and look.
ANDROID APPLICATION LIFE CYCLE (OR)
THE ACTIVITY LIFE CYCLE
In Android, an activity is referred to as one screen in an application. It is very
similar to a single window of any desktop application. An Android app
consists of one or more screens or activities.
Each activity goes through various stages or a lifecycle and is managed by
activity stacks. So when a new activity starts, the previous one always remains
below it. There are four stages of an activity.
1. If an activity is in the foreground of the screen i.e at the top of the stack,
then it is said to be active or running. This is usually the activity that the
user is currently interacting with.
2. If an activity has lost focus and a non-full-sized or transparent activity has
focused on top of your activity. In such a case either another activity has a
higher position in multi-window mode or the activity itself is not focusable
in the current window mode. Such activity is completely alive.
3. If an activity is completely hidden by another activity, it is stopped or
hidden. It still retains all the information, and as its window is hidden thus
it will often be killed by the system when memory is needed elsewhere.
4. The system can destroy the activity from memory by either asking it to
finish or simply killing its process. When it is displayed again to the user, it
must be completely restarted and restored to its previous state.
For each stage, android provides us with a set of 7 methods that have their own
significance for each stage in the life cycle. The image shows a path of
migration whenever an app switches from one state to another.
1. onCreate()
This method is called when the activity is first created. It is responsible for
initializing the activity’s UI, such as inflating the layout and finding the views.
2. onStart()
This method is called when the activity becomes visible to the user. It is a good
place to start animations and other visual changes.
3. onResume()
This method is called when the activity becomes the foreground activity. It is the
state in which the user can interact with the activity. This is where you should
register any listeners or start any services that need to be running while the
activity is in the foreground.
4. onPause()
This method is called when the activity is no longer the foreground activity. It is
a good place to unregister listeners, save any data that needs to be saved, and
stop any services that don’t need to be running in the background.
5. onStop()
This method is called when the activity is no longer visible to the user. It is a
good place to stop animations and other visual changes.
6. onDestroy()
This method is called when the activity is about to be destroyed. It is a good
place to release any resources and clean up any remaining data.
It’s important to note that an activity can also be in a “stopped” state if it
is temporarily obscured by another activity, but it will still retain its state and not
be destroyed. In this case, the onStop() method will be called, but not
onDestroy(). The onRestart() method will be called when the activity becomes
visible again.
CREATING ANDROID ACTIVITY
Step 1: Create a new Android project
- Open Android Studio and create a new project.
- Choose "Empty Activity" as the project template.
Step 2: Create a new Activity
- In the project navigator, right-click on the package name (e.g.,
com.example.myapp").
- Select "New" > "Activity" > "Empty Activity".
- Name the Activity (e.g., "MyActivity").
Step 3: Define the Activity layout
- Create a new layout file (e.g., "activity_my.xml") in the "res/layout" directory.
- Define the user interface elements (e.g., buttons, text views) using XML.
Step 4: Write the Activity code
- Open the Activity Java file (e.g., "MyActivity.java").
- Extend the AppCompatActivity class.
- Override the onCreate() method to inflate the layout and initialize UI elements.
Example code:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// Initialize UI elements
Button button = findViewById(R.id.my_button);
TextView textView = findViewById(R.id.my_text_view);
}
}
Step 5: Declare the Activity in the AndroidManifest.xml
- Open the AndroidManifest.xml file.
- Add the Activity declaration inside the <application> tag:
<activity android:name=".MyActivity"></activity>
Step 6: Run the application
- Connect an Android device or emulator.
- Run the application using the "Run" button or Shift+F10.
VIEWS
In Android development, Views are the basic building blocks of a user interface
(UI), responsible for drawing and handling user interactions. They are
rectangular areas on the screen that display content or respond to user input.
Key Concepts:
View as a Rectangle:
Every View occupies a rectangular area on the screen, even if the content
doesn't fill the entire space.
Superclass:
The android.view.View class is the base class for all UI components in
Android.
Widgets:
Views are often referred to as "widgets" because they represent the visible and
interactive elements of the UI.
Layout Parameters:
Views have layout parameters (like LayoutParams) that define their desired
size and position within their parent container.
Measuring and Drawing:
Views go through a "measure" pass to determine their size based on layout
parameters and content, and then a "draw" pass to render themselves on the
screen.
Event Handling:
Views are responsible for handling user input events like clicks, touches, and
key presses.
Using Views:
In Android, a View is a user interface component that represents a
rectangular area of the screen. Views are the basic building blocks of an
Android application's user interface.
Here are some common types of Views in Android:
1. Text View
Displays text to the user.
2. Edit Text
Allows the user to enter text.
3. Button
A clickable button that can perform an action.
4. Image View
Displays an image.
5. List View
Displays a list of items.
6. Grid View
Displays a grid of items.
7. Recycler View
A more efficient and flexible version of ListView.
8. CheckBox
A checkbox that can be checked or unchecked.
9. Radio Button
A radio button that can be selected.
10. Spinner
A dropdown list of items.
11. ProgressBar
Displays a progress bar.
12. SeekBar
A slider that allows the user to select a value.
13. Rating Bar
A rating system that allows the user to rate something.
14. Web View
Displays a web page.
15. Surface View
A View that provides a dedicated drawing surface.
16. View Flipper
A View that can flip between multiple child Views.
17. View Switcher
A View that can switch between multiple child Views.
18. Linear Layout
A layout that arranges its child Views in a linear fashion.
19. Relative Layout
A layout that arranges its child Views relative to each other.
20. Constraint Layout
A layout that arranges its child Views using constraints.
These are just some of the many Views available in Android.
Each View has its own set of attributes and methods that can be used to
customize its appearance and behavior.
Layouts in Android SDK
Layout Managers (or simply layouts) are said to be extensions of the
View Group class. They are used to set the
position of child Views within the UI we are
building. We can nest the layouts, and
therefore we can create arbitrarily complex
UIs using a combination of layouts.
There is a number of layout classes in
the Android SDK. They can be used,
modified or can create your own to make
the UI for your Views, Fragments and
Activities. You can display your contents
effectively by using the right combination of layouts.
Types of Layouts
1. Constraint Layout
Constraint Layout is
a flexible layout that allows views to
be positioned using
constraints instead of nesting
layouts. It helps in reducing the view
hierarchy and improves performance
by a lot. It is the most popular and recommended layout for designing complex
interfaces in modern Android applications.
2. Linear Layout
A Linear Layout aligns each of the view in a single direction either
a vertical or a horizontal manner. A layout in vertical manner has a single
column of views, whereas in a layout in horizontal manner, has a single row of
views. It supports a weight attribute for each view that can control the relative
size of each view within the available space. However, excessive nesting of
Linear Layouts can lead to performance issues, so it’s best for straightforward
layouts with a few elements.
3. Frame Layout
Frame Layout is a simple layout mainly used to hold a single child view, though
multiple views can be stacked on top of each other. It is commonly used
for overlays, fragments, and simple UI components like image views
4. Relative Layout
Relative layout allows views to be relative to one another or to the
parent layout. This makes positioning flexible as we can position views to the
left, right, top, or bottom of other views. However after Constraint Layout was
introduced, the use of Relative Layout has ceased since Constraint Layout is
much better as handling
large UIs.
5. Table Layout
Table Layout
arranges views in a grid-
like format using rows and
columns, similar to an
HTML table. It is useful for
displaying structured data, such as forms or spreadsheets. Each row consists of
multiple TableRow elements, and views within rows can be assigned specific
column spans.
6. Grid Layout
Introduced in Android 4.0 (API level 14), the GridLayout is an advanced
and more flexible alternative to TableLayout. It divides the screen into a matrix
of rows and columns, allowing precise placement of elements without needing
of nested layouts. It is efficient for creating grid-based UIs like image galleries
or dashboards.
7. Coordinator Layout
Coordinator Layout is an advance layout that provides motion and interactive
capabilities between views. It is mostly used for implementing components like
the Collapsing Toolbars, and swipe-to-dismiss behavior. It allows views to work
based on user actions, such as scrolling, swipe gestures and animations.
Downloading and Installing Android
For Android Applications Development we have to set the environment. This
comprises downloading, configuring, and installing of several software
components required to make the IDE complete and ready for developing
purposes. The prerequisite components to setup our Android IDE are as
follows :
1. Java Development Kit or JDK since Android applications are developed in Java
2. Android Software Development Kit(SDK)
3. Android studio IDE
Setting up the environment for Android development involves configuring our
development environment with the necessary software tools and SDK
components:
1. Install Java Development Kit or(JDK):
Android development requires JDK. Download and install the latest version of
JDK from the official Oracle website
(https://www.oracle.com/java/technologies/javase-jdk15-downloads.html).
And Follow the installation instructions.
2. Install Android Studio:
1. Download Android Studio:
Visit the official Android Studio website
(https://developer.android.com/studio) and click on the "Download" button.
2. Run the Installer:
Once the download is complete, locate the downloaded file and double- click
on it to run the installer.
3. Choose Setup Type:
The installer will prompt us to choose the type of setup we want. We can
choose the Standard setup, which includes the most commonly used
features, or the Custom setup, which allows us to customize the installation
further.
4. Select Components:
In the next step, we’ll be asked to select the components we want to
install. Make sure the "Android Studio" and "Android Virtual Device"
options are checked.
5. Choose Installation Location:
Select the installation location for Android Studio. The default location is
usually fine, but we can choose a different location if we prefer.
6. Choose Start Menu Folder:
Specify the Start Menu folder where short cuts for Android Studio will be
created.
7. Install:
Click on the "Install " button to begin the installation process. The installer
will now download and install the selected components.
8. Launch Android Studio:
Once the installation is complete, we can launch Android Studio by
clicking on the "Finish" button.
9. Set Up Android Studio:
On the first launch, Android Studio will prompt us to import settings from a
previous version (if any) and to customize the setup according to our
preferences.
10. Download SDK Components:
Android Studio will prompt us to download additional SDK components and
system images for the Android versions we want to develop for.
Follow the on-screen instructions to download and install these components.
11. Create a New Project:
After completing the set up, we can create a new Android projector open an
existing one to start developing our app.
3. Configure Android SDK in Android Studio:
After installing Android Studio, launch it. Android Studio will
prompt us to download the necessary SDK components if they 'renot
already installed. For this, we have to follow the on-screen
instructions to download and install the required SDK components.
4. Set Up Android Virtual Device(AVD):
Android Virtual Device (AVD) allows us to test our apps on
virtual devices. Open Android Studio, go to "Tools">"AVD
Manager," and create a new virtual device by following the prompts.
Choose a device definition and system image that we want to emulate.
5. Set Environment Variables:
We might need to set up environment variables for Java and
Android SDK if they are not automatically detected. This step
ensures that other tools can locate the JDK and Android SDK.
Here's how to set environment variables :
● JAVA_HOME:Set this variable to the installation
directory of JDK. For example, C:\Program
Files\Java\jdk15.
● ANDROID_HOME:Set this variable to the installation
directory of Android SDK. For example,
C:\Users\YourUsername\AppData\Local\Android\Sdk.
● Path: Add
%JAVA_HOME%\binand%ANDROID_HOME%\platform-
tools to our system's Path variable To ensure that
commands like java, javac, adb, etc., can be run from the
command line.
6. Install Additional SDK Components:
Depending on our project requirements, we may need to install
additional SDK components. You can do this through the
Android Studio SDK Manager (accessible via "Tools">"SDK
Manager").
7. Update Android Studio and SDK:
Regularly update Android Studio and SDK components to
access the latest features and improvements. You can check for
updates within Android Studio via "Help">"Check for Updates"
and update SDK components through the SDK Manager.
Building or Developing and Exploring the First Android Application:
We have seen that whenever we learn new programming
languages, the first program always displays ‘hello world’ on the
screen. The same trend continues with Android here; yet, we will
write a somewhat comprehensible "hello world" application. It is very
easy and practically no coding is required. However, to make this
application interesting, we will add some extra coding in it.
● Using Android studio IDE to Create an Application:
The use of an IDE is recommended for Android application
development. In this section, we learn the basic steps to create an
Android application using the Android studio IDE.
We are using the Android studio IDE, which is bundled with the
Android SDK. In this IDE, we need to use the New Android
Application wizard to start creating an Android application. Let's
discuss the development of the first Android application, named
“MyFirstApp” .The steps to create a new project in Android studio
IDE are as follows :
1. Install Android Development Tools(ADT):
● Ensure that we have Android studio IDE installed on our
system.
● Install the Android Development Tools(ADT) plugin for
Android studio. We can do this by following the
instructions provided on the official Android Developer
website.
2. Setup Android SDK:
● Download and install the Android SDK if you have not
already.
● Open Android studio and configure it to use the
Android SDK. We can do this by navigating to
Window > Preferences > Android and specifying the
location of the Android SDK on our system.
3. Create a New Android Project:
● In Android studio, goto File>New>Android Application
Project.
● Enter a project name (e.g., Hello World), choose a
package name(e.g., com.example.helloworld), and
select a minimum SDK version.
● Click "Next" and choose a blank activity template for the
project.
● Click "Next" again and customize the activity settings if
needed.
● Click "Finish" to create the project.
4. Navigate to the Main Activity. Java file:
● Expand the project folder in the Package Explorer.
● Navigate to the src>com.example.helloworld directory
(or the package name you specified) and open the
MainActivity.java file.
5. Edit Main Activity.java:
● Inside MainActivity.java, you'll see a method named on
Create. This method is called when the activity is created.
● Within on Create, locate the line set ContentView
(R.layout.activity_main);. This line sets the layout for the
activity.
● We'll edit the activity_main.xml layout file next to create the
UI for our "Hello World" message.
6. Create UI Layout(activity_main.xml):
● Navigate to theres>layout directory.
● Open the activity_main.xmlfile.
● Drag and drop a TextView widget onto the layout.
● Set the text property of the TextViewto "HelloWorld" or any
desired message.
● Optionally,customizetheappearanceoftheTextView(e.g.,f
ontsize,color, alignment).
7. Run the Application:
● Ensure that an Android Virtual Device(AVD)is setup or
connect a physical Android device to your computer.
● Right-click on the project in Android studio
and select Run As>Android Application.
● Choose the AVD or device to run the application on.
● Click "OK" to launch the application.
8. View the Output:
● The emulator o rconnected device should display
the "HelloWorld" message on the screen.
Running Your Application:
The steps to run the "HelloWorld" application (MyFirstApp) on the
Android Emulator as described :
1. Open Android studio IDE and navigate to any directory containing the
MyFirstApp Project in the Package Explorer.
● Click the "Run" icon in the tool bar of Android studio IDE.
● Alternatively, select the application and click on the "Run" option
in the menu bar. We can also choose "Run As" ->"Android
Application."
2. The Android emulator (AVD) will appear as the next window. It
might take some time to boot up, and then the home screen will be
displayed.
3. Click the Applications Icon on the home screen of the emulator. Look
for the ‘MyFirstApp’ application icon.
4. Click on the icon of the ‘MyFirstApp’application.The screen will
display the output, which should be "Hello world!"
By following these steps, we can create and run the "HelloWorld" application
on an Android emulator.