You are on page 1of 16

1:-Android Architecture

Android architecture contains different number of components to support any


android device needs. Android software contains an open-source Linux Kernel
having collection of number of C/C++ libraries which are exposed through an
application framework services.
Among all the components Linux Kernel provides main functionality of operating
system functions to smartphones and Dalvik Virtual Machine (DVM) provide
platform for running an android application.
The main components of android architecture are following:-
 Applications
 Application Framework
 Android Runtime
 Platform Libraries
 Linux Kernel
Pictorial representation of android architecture with several main components
and their sub components –
Applications –
Applications is the top layer of android architecture. The pre-installed
applications like home, contacts, camera, gallery etc and third party applications
downloaded from the play store like chat applications, games etc. will be
installed on this layer only.
It runs within the Android run time with the help of the classes and services
provided by the application framework.
Application framework –
Application Framework provides several important classes which are used to
create an Android application. It provides a generic abstraction for hardware
access and also helps in managing the user interface with application
resources. Generally, it provides the services with the help of which we can
create a particular class and make that class helpful for the Applications
creation.
It includes different types of services activity manager, notification manager,
view system, package manager etc. which are helpful for the development of
our application according to the prerequisite.
Application runtime –
Android Runtime environment is one of the most important part of Android. It
contains components like core libraries and the Dalvik virtual machine(DVM).
Mainly, it provides the base for the application framework and powers our
application with the help of the core libraries.
Like Java Virtual Machine (JVM), Dalvik Virtual Machine (DVM) is a register-
based virtual machine.
and specially designed and optimized for android to ensure that a device can
run multiple instances efficiently. It depends on the layer Linux kernel for
threading and low-level memory management. The core libraries enable us to
implement android applications using the standard JAVA or Kotlin programming
languages.
Platform libraries –
The Platform Libraries includes various C/C++ core libraries and Java based
libraries such as Media, Graphics, Surface Manager, OpenGL etc. to provide a
support for android development.
 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 FreeType 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 (Secure Sockets Layer) is security technology to establish an encrypted
link between a web server and a web browser.
Linux Kernel –
Linux Kernel is heart of the android architecture. It manages all the available
drivers such as display drivers, camera drivers, Bluetooth drivers, audio drivers,
memory drivers, etc. which are required during the runtime.
The Linux Kernel will provide an abstraction layer between the device hardware
and the other components of android architecture. It is responsible for
management of memory, power, devices etc.
The features of Linux kernel are:
 Security: The Linux kernel handles the security between the application and
the system.
 Memory Management: It efficiently handles the memory management thereby
providing the freedom to develop our apps.
 Process Management: It manages the process well, allocates resources to
processes whenever they need them.
 Network Stack: It effectively handles the network communication.
 Driver Model: It ensures that the application works properly on the device and
hardware manufacturers responsible for building their drivers into the Linux
build.
2:-Differntiate between JVM and
DVM.explain in details the Dalvik and
ART.
Difference Table
JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)

Stack-based VM that
Register-based VM that uses registers located
performs arithmetic and logic
in the CPU to perform arithmetic and logic
operations through push and
operations.
pop operands. The result of
JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)

operations is stored in stack


memory.

Source code files are first of all compiled into


Java source code is compiled Java bytecode format like JVM. Further,
into Java bytecode the DEX compiler(dx tool) converts the Java
format(.class file) that further bytecode into Dalvik bytecode(classes.dex) file
translates into machine code. that will be used to create the .apk file.

More information is required


to the VM for data loading
and manipulation as well as
method loading in the stack Instruction size is larger as it needs to encode
data structure. the source and destination register of the VM.

Compiled bytecode size is


compact because the location
of the operand is implicitly on Compiled bytecode size is larger as each
the operand stack. instruction needs all implicit operands.

The executable file for the


device is .jar file. The executable file for the device is .apk file.

A single instance of JVM is


configured with shared
processes and memory space The device runs multiple DVM instances with
in order to run all deployed a separate process in shared memory space to
applications. deploy the code of each application.
JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)

Supports multiple operating


systems like Linux, Windows,
and Mac OS. Support only the Android operation system.

Dalvik
Dalvik Virtual Machine or DVM is a Register-Based virtual machine that was
designed and written by Dan Bornstein. The Dalvik virtual machine was named
by Bornstein after the fishing village “Dalvík” in Eyjafjörður, Iceland, where
some of his ancestors used to live. Dalvik is a discontinued process virtual
machine (VM) in the Android OS that executes applications written for Android.
Dalvik bytecode format is still used as a distribution format, but no longer at
runtime in newer Android versions. Android itself is a Linux system with Dalvik
sitting on top of it. DVM takes android app, turns them from java code into
bytecode that the Linux system can run. Basically, a plain java code is compiled
in the JIT compiler to bytecode during runtime to run on the machine. This could
lead to a slowdown because compilation at runtime especially during runtime is
time-consuming. Hence, manufacturers and OEMs sometimes put out their
applications as odexed. There are 2 types of files:
 .dex(Dalvik Executable file) file is an android’s compiled code file. These
.dex files are then zipped into a single .apk file.
 .odex file is created by the Android operating system to save space and
increase the boot speed of an Android app (a .apk file).
dexopt is used to optimize DEX to ODEX (optimized DEX)which contains the
optimized bytecode. So the whole process in DVM can be summarized as:

DVM is better for low storage devices. But it is slower as compilation is done
after installation.
ART
With a newer android version specifically from 4.4 version KitKat, there is the
concept of ART as an alternative to DVM. ART(Android Run Time) is a
successor of DVM which uses the same bytecode and .dex files (but not .odex
files), with the succession aiming at performance improvements transparent to
the end-users. Android 5.0 “Lollipop” is the first version in which ART is
the only included runtime. Now the thing that ART does is bring apps that are
fully compiled when they’re installed on the device. Therefore, higher
performance as no need to convert code to bytecode then compile. But the
downside is you need more storage space and a little longer to install because
of compilation during installation meaning it has to live on the device all the
time. Hence, instead of relatively small java code, we have larger
bytecode/machine code. You may have heard the terms odexed and de-
odexed. What is done in this instance is you take a small part of the application
and then precompile it they can go ahead and make a portion of their
application optimized to run on their device, and so they’ve now precompiled
that section of the app and the rest of its compiled at runtime. So this makes it
just a little faster and more performant than in Dalvik. But this approach takes a
little more storage space.
Ex: Samsung with TouchWiz .. A lot of stuff, TouchWiz is based on is,
precompiled and hence when these are de-odexed, you can retheme/reskin
them while losing some performance benefits.
Before reading ahead, remember that the dex2oat is used to optimize and
compile .dex into a .oat file which may contain machine code in the ELF format.
ART compiles apps using the on-device dex2oat tool. This utility accepts DEX
files as input and generates a compiled app executable for the target device.
When an app is installed, Android automatically optimizes app data and creates
a corresponding OAT file. An OAT file is created by the Android operating
system in order to speed up the loading time of an Android app (.APK
file). Android uses this file to load the app more quickly, creating a better user
3:-Broadcast Receiver in Android With
Example
Broadcast in android is the system-wide events that can occur when the device
starts, when a message is received on the device or when incoming calls are
received, or when a device goes to airplane mode, etc. Broadcast Receivers are
used to respond to these system-wide events. Broadcast Receivers allow us to
register for the system and application events, and when that event happens,
then the register receivers get notified. There are mainly two types of Broadcast
Receivers:
 Static Broadcast Receivers: These types of Receivers are declared in the
manifest file and works even if the app is closed.
 Dynamic Broadcast Receivers: These types of receivers work only if the app
is active or minimized.
Since from API Level 26, most of the broadcast can only be caught by the
dynamic receiver, so we have implemented dynamic receivers in our sample
project given below. There are some static fields defined in the Intent class which
can be used to broadcast different events. We have taken a change of airplane
mode as a broadcast event, but there are many events for which broadcast
register can be used. Following are some of the important system-wide generated
intents:-

Intent Description Of Event

Indicates low battery


condition on the
android.intent.action.BATTERY_LOW : device.

This is broadcast
once after the system
android.intent.action.BOOT_COMPLETED has finished booting

To perform a call to
someone specified by
android.intent.action.CALL the data

Indicates that the


android.intent.action.DATE_CHANGED date has changed
Indicates that the
device has been a
android.intent.action.REBOOT reboot

The mobile network


or wifi connection is
android.net.conn.CONNECTIVITY_CHANGE changed(or reset)

This indicates that


airplane mode has
been switched on or
android.intent.ACTION_AIRPLANE_MODE_CHANGED off.

The two main things that we have to do in order to use the broadcast receiver in
our application are:
Creating the Broadcast Receiver:
class AirplaneModeChangeReceiver:BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// logic of the code needs to be written here
}
}

Registering a BroadcastReceiver:
IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED).also {
// receiver is the broadcast receiver that we have registered
// and it is the intent filter that we have created
registerReceiver(receiver,it)
}

Example

Below is the sample project showing how to create the broadcast Receiver and
how to register them for a particular event and how to use them in the application.
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a
New Project in Android Studio.

Step 2: Working with the activity_main.xml file


Go to the activity_main.xml file and refer to the following code. Below is the code
for the activity_main.xml file.

Step 3: Working with the MainActivity file


Go to the MainActivity file and refer to the following code. Below is the code for
the MainActivity file. Comments are added inside the code to understand the
code in more detail.

Step 4: Create a new class


Go to app > java > your package name(in which the MainActicity is present)
> right-click > New > Kotlin File/Class and name the files
as AirplaneModeChangeReceiver. Below is the code for
the AirplaneModeChangeReceiver file. Comments are added inside the code
to understand the code in more detail.

4:-position sensors
Position sensor are devices that can detect the movement of an object or
determine its relative position measured from an established reference point.
These types of sensors can also be used to detect the presence of an object
or its absence.
Types of Position Sensors
Potentiometric Position Sensors
Potentiometric Position Sensors are resistance-based sensors that use a resistive track with a wiper that
is attached to the object whose position is being monitored.

Inductive Position Sensors


Inductive position sensors detect the position of an object by changes in the characteristics of a
magnetic field that is induced in the coils of the sensor.

Eddy Current-Based Position Sensors


Eddy currents are induced currents that occur in a conductive material that is in the presence of a
changing magnetic field and are a result of Faraday’s law of induction.

Capacitive Position Sensors


Capacitive position sensors rely on detecting a change in capacitance value to establish the position of
the object being measured. Capacitors consist of two plates separated from each other with a dielectric
material between the plates.

MotionSEnsor
A motion sensor (or motion detector) is an electronic device that is designed to detect and measure
movement. Motion sensors are used primarily in home and business security systems, but they can also
be found in phones, paper towel dispensers, game consoles, and virtual reality systems.

There are two types of motion sensors:


active motion sensors and passive motion sensors. Active sensors have both a transmitter and a
receiver. This type of sensor detects motion by measuring changes in the amount of sound or radiation
reflecting back into the receiver.

5:-Profile guided optimization


Profile-guided optimization (PGO) is a well known compiler optimization

technique. In PGO, runtime profiles from a program’s executions are used

by the compiler to make optimal choices about inlining and code layout.

This leads to improved performance and reduced code size. Developers can

now leverage Google’s toolkit to easily deploy PGO tools and improve their

native Android apps.

PGO can be deployed to your application or library with the


following steps:
1. Identify a representative workload.

2. Collect profiles.

3. Use the profiles in a Release build.


Step 1: Identify a Representative Workload

First, identify a representative benchmark or workload for your


application. This is a critical step as the profiles collected from the
workload identify the hot and cold regions in the code. When using the
profiles, the compiler will perform aggressive optimizations and
inlining in the hot regions. The compiler may also choose to reduce the
code size of cold regions while trading off performance.

Step 2: Collect Profiles

The profiles are collected by running the workload from step 1 on an


instrumented build of the application. To generate an instrumented
build, add -fprofile-generate to the compiler and linker flags. This flag
should be controlled by a separate build variable since the flag is not
needed during a default build.

Profiles get collected when the instrumented binary is run and get
written to a file at exit. However, functions registered with atexit are
not called in an Android app — the app just gets killed. The
application/workload has to explicitly trigger a profile write by calling
the __llvm_profile_write_file function.

Writing the profile file is simpler if the workload is a standalone binary


— just set the LLVM_PROFILE_FILE environment variable before
running the binary.
The profile files are in the .profraw format. Use the llvm-profdata utility
in the NDK to convert from .profraw to .profdata, which can then be
passed to the compiler.
Use the llvm-profdata and clang from the same NDK release to avoid
version mismatch of the profile file formats.

Step 3 Use the Profiles to Build Application

Use the profile from the previous step during a release build of your
application by passing -fprofile-use=<>.profdata to the compiler and
linker. The profiles can be used even as the code evolves — the Clang
compiler can tolerate slight mismatch between the source and the
profiles.

6:- Install Android Studio


To install Android Studio on Windows, follow these steps:

 If you downloaded an .exe file (recommended), double-click to launch it.


 If you downloaded a .zip file:
1. Unpack the .zip.
2. Copy the android-studio folder into your Program Files folder.
3. Open the android-studio > bin folder.
4. Launch studio64.exe (for 64-bit machines) or studio.exe (for 32-bit machines).
5. Follow the Setup Wizard in Android Studio and install any recommended SDK
packages.

Configure Android Studio


Android Studio provides wizards and templates that verify your system requirements,
such as the Java Development Kit (JDK) and available RAM, and configure default
settings, such as an optimized default Android Virtual Device (AVD) emulation and
updated system images. This document describes additional configuration settings to
customize your use of Android Studio.

Android Studio provides access to two configuration files through the Help menu:

 studio.vmoptions: Customize options for Android Studio's Java Virtual Machine (JVM),
such as heap size and cache size. Note that on Linux machines this file may be
named studio64.vmoptions, depending on your version of Android Studio.
 idea.properties: Customize Android Studio properties, such as the plugins folder path or
maximum supported file size.

7:-HttpUrlConnection
A URLConnection with support for HTTP-specific features. See the spec for details.

Uses of this class follow a pattern:

1. Obtain a new HttpURLConnection by calling URL.openConnection() and casting the result


to HttpURLConnection.
2. Prepare the request. The primary property of a request is its URI. Request headers may
also include metadata such as credentials, preferred content types, and session
cookies.
3. Optionally upload a request body. Instances must be configured with setDoOutput(true) if
they include a request body. Transmit data by writing to the stream returned
by URLConnection.getOutputStream().
4. Read the response. Response headers typically include metadata such as the response
body's content type and length, modified dates and session cookies. The response body
may be read from the stream returned by URLConnection.getInputStream(). If the response
has no body, that method returns an empty stream.
5. Disconnect. Once the response body has been read, the HttpURLConnection should be
closed by calling disconnect(). Disconnecting releases the resources held by a connection
so they may be closed or reused.

For example, to retrieve the webpage at http://www.android.com/:


URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
try {
InputStream in = new
BufferedInputStream(urlConnection.getInputStream());
readStream(in);
} finally {
urlConnection.disconnect();
}

8:- differentiate local and remote service


Remote services
A remote service is a process that resides outside of the application server and provides a
service to the application. An example of a remote service is a web service, message queue, or caching
server. remote service runs in different process and may be in different application. You can access a
remote service which is running in the different application.

Local services
Local Services means works or services performed or supplied by a Local Enterprise. Local
Services means local goods and services provided or to be provided by the Local Supplier under the
terms of the Local Contracts. Local service means it runs in the same process probably in the same
application. You can start a service using the method startService() and you can stop the service by using
the method stopService(). These two life cycle methods or Service And remote service are generally run
in a different application. you can access them by writing AIDL Interfaces and you can attach to a remote
service by using binder. Local service runs in the same process. you can't access a local service that is
running in a different application.

9:- Android Virtual Device (AVD),


The Android emulator is an Android Virtual Device (AVD), which represents a specific
Android device. We can use the Android emulator as a target device to execute and test our
Android application on our PC. The Android emulator provides almost all the functionality of a
real device. We can get the incoming phone calls and text messages. It also gives the location of
the device and simulates different network speeds. Android emulator simulates rotation and
other hardware sensors. It accesses the Google Play store, and much more.

10:-Name the android version with their API


levels.
API Level is an integer value that uniquely identifies the framework API
revision offered by a version of the Android platform.

Version SDK / API level Version Codename


code
Android 13 Level 33 TIRAMISU
Tiramisu 2

Android 11 Level 30 R
Red Velvet Cake 2

Android 10 Level 29 Q
Quince Tart 2
Android 9 Level 28 P
Pie

11:-working of Telephony Manager


The android.telephony.TelephonyManager class provides information about the
telephony services such as subscriber id, sim serial number, phone network type etc.
Moreover, you can determine the phone state etc.

Android TelephonyManager Example


Let's see the simple example of TelephonyManager that prints information of the
telephony services.

activity_main.xml

12:-concept of Animation and Graphics


Animation is a method by which still figures are manipulated to appear as moving images.
In traditional animation, images are drawn or painted by hand on transparent celluloid sheets to
be photographed and exhibited on film. Today, most animations are made with computer-
generated imagery (CGI).

make your document more appealing to read by breaking up large blocks of information.
They’re like an oasis for the eye in a text desert.set the tone for the overall message of
your document, whether it be hope, progress, innovation etc.help explain complex
topics and processes by simplifying them with visuals.highlight key info such as
quotations and stats to allow for easy skimming.

You might also like