0% found this document useful (0 votes)
12 views

Lec 11.advanced Android Programming Topics

Uploaded by

abdul.payziwiut
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lec 11.advanced Android Programming Topics

Uploaded by

abdul.payziwiut
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Mobile Application Development

Lecture 11. Advanced Android programming topics.


Android OS Architecture
Platform architecture
Android is an open source,
Linux-based software
stack created for a wide
array of devices and form
factors.

System apps
Java API Framework
Native C/C++ Libraries
Hardware Abstraction
Layer
Linux Kernel
Source: https://developer.android.com/guide/platform
Linux Kernel
The foundation of the Android platform
is the Linux kernel.

The Linux kernel has been in


widespread use for years, and is used
in millions of security-sensitive
environments. Through its history of
constantly being researched, attacked,
and fixed by thousands of developers,
Linux has become a stable and secure
kernel trusted by many corporations
and security professionals.

It allows device manufacturers to


develop hardware drivers for a well-
Source:https://source.android.com/docs/security/overview/kernel-security
known kernel.
Hardware Abstraction Layer (HAL)
The hardware abstraction layer (HAL)
provides standard interfaces that
expose device hardware capabilities to
the higher-level Java API framework.

The HAL consists of multiple library


modules, each of which implements an
interface for a specific type of
hardware component, such as the
camera or bluetooth module. When a
framework API makes a call to access
device hardware, the Android system
loads the library module for that
hardware component.
Source: https://developer.android.com/guide/platform
Android Runtime
Each Android app runs in its own
process and with its own instance of
the Android Runtime (ART). ART is
written to run multiple virtual machines
on low-memory devices by executing
DEX files, a bytecode format designed
specially for Android that's optimized
for minimal memory footprint.

Android also includes a set of core


runtime libraries that provide most of
the functionality of the Java
programming language.

Source: https://developer.android.com/guide/platform
Native C/C++ Libraries
Many core Android system components
and services, such as ART and HAL, are
built from native code that require
native libraries written in C and C++.
The Android platform provides Java
framework APIs to expose the
functionality of some of these native
libraries to apps.

If you are developing an app that


requires C or C++ code, you can use
the Android NDK to access some of
these native platform libraries directly
from your native code.
Source: https://developer.android.com/guide/platform
Java API Framework
The entire feature-set of the Android OS
is available to you through APIs written
in the Java language. These APIs form
the building blocks you need to create
Android apps by simplifying the reuse of
core, modular system components and
services, which include the following:

Developers have full access to the


same framework APIs that Android
system apps use.

Source: https://developer.android.com/guide/platform
System Apps
Android comes with a set of core apps
for email, SMS messaging, calendars,
internet browsing, contacts, and more.

The system apps function both as apps


for users and to provide key capabilities
that developers can access from their
own app. For example, if your app would
like to deliver an SMS message, you
don't need to build that functionality
yourself—you can instead invoke
whichever SMS app is already installed
to deliver a message to the recipient
you specify.
Source: https://developer.android.com/guide/platform
Four main application
components
Application 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.
There are four different types of app components:

• 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
Source: https://developer.android.com/guide/components/fundamentals
Four main application components:
Activities
Activity
An activity is the entry point for interacting with the user. It represents a
single screen with a user interface. For example, an email app might have
one activity that shows a list of new emails, another activity to compose an
email, and another activity for reading emails.

Although the activities work together to form a cohesive user experience in


the email app, each one is independent of the others. As such, a different app
can start any one of these activities if the email app allows it.

Source: https://developer.android.com/guide/components/fundamentals
Activity
An activity facilitates the following key interactions between system and app:

• Keeping track of what the user currently cares about (what is on screen) to ensure
that the system keeps running the process that is hosting the activity.
• Knowing that previously used processes contain things the user may return to
(stopped activities), and thus more highly prioritize keeping those processes around.
• Helping the app handle having its process killed so the user can return to activities
with their previous state restored.
• Providing a way for apps to implement user flows between each other, and for the
system to coordinate these flows. The most classic example is file sharing.

Source: https://developer.android.com/guide/components/fundamentals
Four main application components:
Services
Service
A service is a general-purpose entry point for keeping
an app running in the background for all kinds of
reasons. It is a component that runs in the background
to perform long-running operations or to perform work
for remote processes.

A service does not provide a user interface. For


example, a service might play music in the background
while the user is in a different app, or it might fetch data
over the network without blocking user interaction with
an activity.

Source: https://developer.android.com/guide/components/fundamentals
Foreground services
A foreground service performs some operation that
is noticeable to the user. For example, an audio app
would use a foreground service to play an audio
track. Foreground services must display a
Notification. Foreground services continue running
even when the user isn't interacting with the app.

Source: https://developer.android.com/guide/components/services
Background services
A background service performs an operation that isn't directly noticed by
the user. For example, alarm clock service.

If the app targets API level 26 or higher, the system imposes restrictions on
running background services when the app itself isn't in the foreground. In
most situations, for example, you shouldn’t access location information from
the background.

Source: https://developer.android.com/guide/components/services
Bound services
Bound services run because some other app (or the system) has said that it
wants to make use of the service. This is basically the service providing an
API to another process.

A bound service runs only as long as another application component is


bound to it. Multiple components can bind to the service at once, but when
all of them unbind, the service is destroyed.

Simple example is file downloading. The application can bind to some File
Downloader Service.

Source: https://developer.android.com/guide/components/services
Four main application components:
Broadcast receivers
Broadcast receivers
A broadcast receiver is a component that enables the system to deliver
events to the app outside of a regular user flow. The system can deliver
broadcasts even to apps that aren't currently running.

Apps can register to receive specific broadcasts. When a broadcast is sent,


the system automatically routes broadcasts to apps that have subscribed to
receive that particular type of broadcast.

Generally speaking, broadcasts can be used as a messaging system across


apps and outside of the normal user flow. For example, battery level change
can broadcast the message and interested applications can receive it.

Source: https://developer.android.com/guide/components/broadcasts
Broadcast receivers
A popular example of Broadcast
receiver usage is handling Push
notifications.

Inside the application a custom


Broadcast Receiver class is created
and when device receives a push
notification onReceive() method
gets called inside the class. So that the
application can read the push message
and react.
Four main application components:
Content providers
Content provider
Content providers can help an application
manage access to data stored by itself,
stored by other apps, and provide a way to
share data with other apps. They encapsulate
the data, and provide mechanisms for
defining data security. Content providers are
the standard interface that connects data in
one process with code running in another
process.

For example, Contacts applications.

Source: https://developer.android.com/guide/topics/providers/content-providers
Content provider
Content providers provide a nice way of abstraction for your data source. It
allows you to swap a data source without affecting any of the applications
that are using it.

Use content providers


if you plan to share data.

Source: https://developer.android.com/guide/topics/providers/content-providers
Activating components
Application components
A unique aspect of the Android system design is that any app can start
another app’s component. For example, if you want the user to capture a
photo with the device camera, there's probably another app that does that and
your app can use it instead of developing an activity to capture a photo
yourself.

Unlike apps on most other systems, Android apps don't have a single
entry point (there's no main() function).

Source: https://developer.android.com/guide/components/fundamentals
Activating components
Activities, services, and broadcast receivers—are activated by an
asynchronous message called an “intent”. Intents bind individual
components to each other at runtime

An intent is created with an Intent object, which defines a message to


activate either a specific component (explicit intent) or a specific type of
component (implicit intent).

Source: https://developer.android.com/guide/components/fundamentals
The manifest file
Before the Android system can start an app component,
the system must know that the component exists by
reading the app's manifest file, AndroidManifest.xml.
Your app must declare all its components in this file,
which must be at the root of the app project directory.

Source: https://developer.android.com/guide/components/fundamentals
Coursework Questions?
Recommended resources

https://developer.android.com/guide/platform
https://developer.android.com/guide/components/fundamentals
https://developer.android.com/guide/components/activities/intro-activities
https://developer.android.com/guide/components/services
https://developer.android.com/guide/components/broadcasts
https://developer.android.com/guide/topics/providers/content-providers

You might also like