Professional Documents
Culture Documents
1:-Android Architecture
1:-Android Architecture
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)
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:-
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
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.
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.
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.
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
2. Collect profiles.
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.
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.
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.
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.
Android 11 Level 30 R
Red Velvet Cake 2
Android 10 Level 29 Q
Quince Tart 2
Android 9 Level 28 P
Pie
activity_main.xml
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.