2 Android Application Fundamentals
2 Android Application Fundamentals
An android component is simply a piece of code that has a well-defined life cycle e.g. Activity,
Receiver, and Service etc.
The core building blocks or fundamental components of android are activities, views,
intents, services, content providers, fragments and AndroidManifest.xml.
Activity
An activity is a class that represents a single screen. It is like a Frame in AWT (Abstract Window
Toolkit).
View
A view is the UI element such as button, label, text field etc. Anything that you see is a view.
Intent
For example, you may write the following code to view the webpage.
Service
Service is a background process that can run for a long time. There are two types of services
local and remote. Local service is accessed from within the application whereas remote service
is accessed remotely from other applications running on the same device.
BSCS SEVENTH SEMESTER FALL 2023 MOBILE APPLICATION AND DEVELOPMENT 2|P a g e
Content Provider
Fragment
Fragments are like parts of activity. An activity can display one or more fragments on the screen
at the same time.
AndroidManifest.xml
It contains information about activities, content providers, permissions etc. It is like the web.xml
file in Java EE.
It is used to test the android application without the need for mobile or tablet etc. It can be
created in different configurations to emulate different types of real devices.
Application Fundamentals:
Android apps can be written using Kotlin, Java, and C++ languages. The Android SDK tools
compile your code along with any data and resource files into an APK or an Android App
Bundle.
An Android package, which is an archive file with an .apk suffix, contains the contents of an
Android app that are required at runtime and it is the file that Android-powered devices use to
install the app.
An Android App Bundle, which is an archive file with an .aab suffix, contains the contents of an
Android app project including some additional metadata that is not required at runtime.
When distributing your app through Google Play, for example, Google Play's servers generate
optimized APKs that contain only the resources and code that are required by a particular
device that is requesting the installation of the app.
Security sandbox:
(Android has another layer of protection in that it doesn't give one app access to the resource of
another app. This is known as the 'sandbox' where every app gets to play in its own
sandbox and can't use another app's toys!)
Each Android app lives in its security sandbox, protected by the following Android security
features:
BSCS SEVENTH SEMESTER FALL 2023 MOBILE APPLICATION AND DEVELOPMENT 3|P a g e
The Android operating system is a multi-user Linux system in which each app is a different user.
By default, the system assigns each app a unique Linux user ID (the ID is used only by the
system and is unknown to the app). The system sets permissions for all the files in an app so
that only the user ID assigned to that app can access them.
Each process has its virtual machine (VM), so an app's code runs in isolation from other apps.
By default, every app runs in its own Linux process. The Android system starts the process
when any of the app's components need to be executed, and then shuts down the process
when it's no longer needed or when the system must recover memory for other apps.
The Android system implements the principle of least privilege. That is, each app, by default,
has access only to the components that it requires to do its work and no more. This creates a
very secure environment in which an app cannot access parts of the system for which it is not
given permission. However, there are ways for an app to share data with other apps and for an
app to access system services:
It's possible to arrange for two apps to share the same Linux user ID, in which case they are
able to access each other's files. To conserve system resources, apps with the same user ID
can also arrange to run in the same Linux process and share the same VM. The apps must also
be signed with the same certificate.
An app can request permission to access device data such as the device's location, camera,
and Bluetooth connection. The user has to explicitly grant these permissions.
App Components:
App components are the essential building blocks of an Android app. Each component is an
entry point through which the system or a user can enter your app. Some components depend
on others.
Activities
Services
Broadcast receivers
Content providers
Each type serves a distinct purpose and has a distinct lifecycle that defines how the component
is created and destroyed. The following sections describe the four types of app components.
BSCS SEVENTH SEMESTER FALL 2023 MOBILE APPLICATION AND DEVELOPMENT 4|P a g e
Activities
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.
Services
A service is a component that runs in the background to perform long-running operations. For
example, a service might play music in the background while the user is in a different
application, or it might fetch data over the network without blocking user interaction with an
activity.
Broadcast receivers
Broadcast Receivers simply respond to broadcast messages from other applications or from the
system. For example, 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.
Content providers
A content provider component supplies data from one application to others on request. Such
requests are handled by the methods of the ContentResolver class. The data may be stored in
the file system, the database or somewhere else entirely.
A content provider is implemented as a subclass of ContentProvider class and must
implement a standard set of APIs that enable other applications to perform transactions.
BSCS SEVENTH SEMESTER FALL 2023 MOBILE APPLICATION AND DEVELOPMENT 5|P a g e
Additional Components:
There are additional components which will be used in the construction of above mentioned
entities, their logic, and wiring between them. These components are –
A Fragment is a piece of an activity which enable more modular activity design. It will not be
wrong if we say, a fragment is a kind of sub-activity.
Following are important points about fragment −
A fragment has its own layout and its own behaviour with its own life cycle.
You can add or remove fragments in an activity while the activity is running.
You can combine multiple fragments in a single activity to build a multi-pane UI.
A fragment can be used in multiple activities.
Fragment life cycle is closely related to the life cycle of its host activity which means
when the activity is paused, all the fragments available in the activity will also be
stopped.
A fragment can implement a behaviour that has no user interface component.
Prior to fragment introduction, we had a limitation because we can show only a single activity
on the screen at one given point in time. So we were not able to divide device screen and
control different parts separately. But with the introduction of fragment we got more flexibility
and removed the limitation of having a single activity on the screen at a time. Now we can have
a single activity but each activity can comprise of multiple fragments which will have their own
layout, events and complete life cycle.
BSCS SEVENTH SEMESTER FALL 2023 MOBILE APPLICATION AND DEVELOPMENT 6|P a g e
The application can embed two fragments in Activity A, when running on a tablet-sized device.
However, on a handset-sized screen, there's not enough room for both fragments, so Activity A
includes only the fragment for the list of articles, and when the user selects an article, it starts
Activity B, which includes the second fragment to read the article.
Onboarding Screen:
This screen is also called one time screen of an android app. One time screen because it only displays only
for one-time, after that it won’t show until the application is reinstalled.
Walkthrough and onBoarding screens are screens for first-time users of the android app.
First-time users are those users who download and install the application and use it for the first time.
It may be called a startup guide of an app. Instate of Splash Screen which we have created earlier, we have
to create the onboarding screens of our android app.
Splash Screen:
Splash Screen is most commonly the first startup screen which appears when App is opened. In
other words, it is a simple constant screen for a fixed amount of time which is used to display
the company logo, name, advertising content etc.
Normally it shows when app is first time launched on android device or it may be some kind of
process that is used to show screen to user just before the app loads completely.