Android Application Structure
| Simple Hello World Program
Android Application File Structure
• Android application contains different
components such as java source code,
string resources, images, manifest file,
apk file etc.
• Let's understand the project structure
of android application.
Modules
• Module is a collection of source files and build settings that
allow to divide the project into discrete units of functionality
• [Link] app module
• Provides a container for app’s source code, resource files, and app
level settings like module level build file and Android Manifest file
• Major sub divisions are
• Manifest
• java
• Res
1. [Link]: Every project in Android includes a
manifest file, which is [Link], stored in the root
directory of its project hierarchy
• It defines the structure and metadata of our application, its
components, and its requirements.
• This file includes nodes for each of the Activities, Services,
Content Providers and Broadcast Receiver that make the
application and using Intent Filters and Permissions,
determines how they co-ordinate with each other and other
applications.
2. Java:
The Java folder contains the Java source code files.
These files are used as a controller for controlled UI (Layout
file).
It gets the data from the Layout file and after processing that
data output will be shown in the UI layout.
It works on the backend of an Android application.
[Link]: Resource folder is the most important folder because it
contains all the non-code sources like images, XML layouts, UI
strings for our android application
Major subdivisions are
Drawable
Layout
Mipmaps
Values
Drawable:
A Drawable folder contains resource type file (something that
can be drawn).
Drawables may take a variety of file like Bitmap (PNG,
JPEG), Nine Patch, Vector (XML), Shape, Layers, States,
Levels, and Scale.
layout:
Defines the visual structure for a user interface, such as the UI
for an Android application.
This folder stores Layout files that are written in XML
language.
Mipmap:
contains [Link] files to define icons which are used to
show on the home screen.
• Values: Values folder contains a number of XML files like
strings, dimens, colors and styles definitions.
• [Link]: contains color resources of the Android
application.
• Different color values are identified by a unique name that
can be used in the Android application program.
• [Link]: contains string resources of the Android
application.
• The different string value is identified by a unique name that
can be used in the Android application program.
• This file also stores string array by using XML language.
• [Link]: The [Link] file contains resources of the
theme style in the Android application.
• This file is written in XML language.
• 2. Gradle script
• Gradle is a build system (open source) which is used to automate
building, testing, deployment etc. “[Link]” are scripts where
one can automate the tasks
• Every Android project needs a gradle for generating an apk from
the .java and .xml files in the project.
• a gradle takes all the source files (java and XML) and apply
appropriate tools, e.g., converts the java files into dex files and
compresses all of them into a single file known as apk that is
actually used.
• Two types of [Link] scripts
• Top-level [Link]
• Module-level [Link]
Fragment
• When a screen is large, it becomes difficult to manage all of
its functionality in a single activity.
• Fragments are like sub-activities, and an activity can display
one or more fragments on the screen at the same time.
• When a screen is small, an activity contain just one fragment
Intent
• Intent is used to invoke components
• “intention” to do some work
• Intents can be used to perform the following tasks:
• Broadcast a message.
• Start a service.
• Launch an activity.
• Display a web page or a list of contacts.
• Dial a phone number or answer a phone call.
Intent
• Intents are not always initiated by application—they’re also
used by the system to notify application of specific events
(such as the arrival of a text message).
• Intents can be explicit or implicit.
• If you simply say that you want to display a URL, the system
decides what component will fulfill the intention.
• You can also provide specific information about what should
handle the intention.
Content Provider
• Content Providers are used to share data between the
applications.
• Android defines a standard mechanism for applications to
share data without exposing the underlying storage, structure,
and implementation through content providers
Service
• Service is a background process that can run for a long time.
• Android service is a component that is used to perform
operations on the background such as playing music, handle
network transactions, interacting content providers etc.
• It doesn't has any UI
• two types of services:
• Local services are components that are only accessible by the
application that is hosting the service.
• Remote services are services that are meant to be accessed
remotely by other applications running on the device
Broadcast receiver
• Broadcast receiver is an Android component which allows
you to send or receive Android system or application events. .
• All registered receivers for an event are notified by the
Android runtime once this event happens.
• For example, applications can register for various system
events like boot complete or battery low, and Android system
sends broadcast when specific event occur.
• Applications can also initiate broadcasts to let other
applications know that some data has been downloaded to
the device and is available for them to use, so this is broadcast
receiver who will intercept this communication and will
initiate appropriate action.
[Link]
• Defines the contents and behavior of your application
• It contains informations about activities, content providers,
permissions etc.
• For example, it lists your application’s activities and services,
along with the permissions and features the application
needs to run.