Huzaifa Waheed Fa18-Bse-029: Activity

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Huzaifa Waheed

Fa18-bse-029

Q1. Write the purpose, functionalities/role of the following in android application


development:

a) Activity

b) Layout file

c) Androidmanifest.xml file

d) Res folder

e) Gradle script file

Activity:
An activity represents a single screen in your app with which your user can perform a
focussed task such as dial the phone, take a photo, send an email, or view a map. Activities
are usually presented to the user as full-screen windows.

An app usually consists of multiple activities that are loosely bound to each other. Typically,
one activity in an application is specified as the "main" activity, which is presented to the
user when the app is launched. Each activity can then start other activities in order to
perform different actions.

Each time a new activity starts, the previous activity is stopped, but the system preserves the
activity in a stack (the "back stack"). When a new activity starts, that new activity is pushed
onto the back stack and takes user focus. The back stack abides to the basic "last in, first
out" stack mechanism, so, when the user is done with the current activity and presses the
Back button, that current activity is popped from the stack (and destroyed) and the previous
activity resumes.

An activity represents a single screen with a user interface,in-short Activity performs actions on
the screen. 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. If an
application has more than one activity, then one of them should be marked as the activity that
is presented when the application is launched. The activity  class is a crucial component of an
Android app, and the way activities are launched and put together is a fundamental part of the
platform's application model. Unlike programming paradigms in which apps are launched with a
main() method, the Android system initiates code in a activity instance by invoking specific
callback methods that correspond to specific stages of its lifecycle.

Layout file:
. A layout defines the structure for a user interface in your app, such as in an activity. All elements
in the layout are built using a hierarchy of View and ViewGroup objects. A View usually draws something
the user can see and interact with.

A layout defines the visual structure for a user interface, such as UI for an activity or app widget. You can
declare a layout in two ways

1. Declare UI elements in XML: android provides a straight forward XML vocabulary that
corresponds to the view classes and sub classes , such as those for widgets and layouts
2. Instantiate layout elements at run time: your application can create view and view group
objects programmatically

The Android framework gives us the flexibility to use either or both of these methods for declaring and
managing our application's UI. For example, you could declare your application's default layouts in XML,
including the screen elements that will appear in them and their properties. You could then add code in
your application that would modify the state of the screen objects, including those declared in XML, at
run time. The advantage to declaring your UI in XML is that it enables you to better separate the
presentation of your application from the code that controls its behavior. Your UI descriptions are
external to your application code, which means that you can modify or adapt it without having to modify
your source code and recompile. For example, you can create XML layouts for different screen
orientations, different device screen sizes, and different languages. Additionally, declaring the layout in
XML makes it easier to visualize the structure of your UI, so it's easier to debug problems. As such, this
document focuses on teaching you how to declare your layout in XML. If you're interested in
instantiating View objects at runtime, refer to the ViewGroup and View class references.

Androidmanifest.xml file:
Every app project must have an AndroidManifest. xml file at the root of the project source set. Every
project in Android includes a manifest file, which is AndroidManifest.xml, stored in the root directory of
its project hierarchy. The manifest file is an important part of our app because 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.
The manifest file also specifies the application metadata, which includes its icon, version number,
themes etc. and additional top- level nodes can specify any required permissions, unit tests and define
hardware, screen, or platform requirements.

The manifest file describes essential information about your app to the Android build tools,
the Android operating system, and Google Play.

It contains information about package and it also performs the following functions

 It names the Java package for the application. The package name serves as a unique identifier
for the application.
 It determines which processes will host application components.
 It declares the minimum level of the Android API that the application requires
 It lists the libraries that the application must be linked against.
 It declares which permissions the application must have in order to access protected parts of the
API and interact with other applications.
 It also declares the permissions that others are required to have in order to interact with the
application's components.

Res folder :
The res/values folder is used to store the values for the resources that are used in
many Android projects to include features of color, styles, dimensions etc.

Resources are the additional files and static content that your code uses, such as bitmaps, layout
definitions, user interface strings, animation instructions, and more. ... At runtime, Android uses the
appropriate resource based on the current configuration. App resources such as bitmaps and layouts are
organized into type-specific directories inside each module's res/ directory. You can also add alternative
versions of each file that are optimized for different device configurations (such as a high-res version of a
bitmap for high-density screens).

You should always externalize resources such as images and strings from your application code, so that
you can maintain them independently. Externalizing your resources also allows you to provide
alternative resources that support specific device configurations such as different languages or screen
sizes, which becomes increasingly important as more Android-powered devices become available with
different configurations.
In order to provide compatibility with different configurations, you must organize resources in your
project's res/ directory, using various sub-directories that group resources by type and configuration.
Also resource folder contains images of different resolutions of android devices.

For any type of resource, you can specify default and multiple alternative resources for your application.

For example, while your default UI layout is saved in the res/layout/ directory, you might specify a
different layout to be used when the screen is in landscape orientation, by saving it in theres/layout-
land/ directory. Android automatically applies the appropriate resources by matching the device's
current configuration to your resource directory names.

Gradle script file:


Gradle is a build system (open source) which is used to automate building, testing, deployment etc.
“Build.gradle” are scripts where one can automate the tasks. For example, the simple task to copy some
files from one directory to another can be performed by Gradle build script before the actual build
process happens.

Why is Gradle needed?

Every Android project needs a gradle for generating an apk from the .java and .xml files in the project.
Simply put, 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.
There are two types of build.gradle scripts
 Top-level build.gradle
 Module-level build.gradle
Top-level build.gradle:
It is located in the root project directory and its main function is to define the build configurations that
will be applied to all the modules in the project. 

Module-level build.gradle:
Located in the project/module directory of the project this Gradle script is where all the dependencies
are defined and where the sdk versions are declared. This script has many functions in the project which
includes additional build types and override settings in the main/app manifest or top-level
build.gradle file

----------------------------------------------------------------------------------------

You might also like