A (175)

(Tuis.) #1
CHAPTER 3: An Introduction to the Android Application Development Platform 65

When the user first launches an Android application by clicking the launch icon, the DVM at that
time creates a runtime binary version of your application, by using your application’s DEX file. This is
called just-in-time (JIT) software execution. The runtime binary (zeroes and ones) will be compatible
with the specific type of CPU that is being used in that particular Android device.


Android then creates a process (more on these in Chapter 13) that will then allocate memory and
CPU processing resources (processor time slices) for your application, so that it has the resources
it needs to perform its various functions. Each time an application is launched, and a process
spawned, an instance of the DVM is created for that process and an allocation of that Android
device memory space is designated or reserved for your application.


An instance is a reference to where the DVM is stored in system memory. Instancing can save
loads of memory, and in fact it is used in 3D software in the modeling process to reduce the
amount of actual data that is required to generate a 3D model that features a repetition of identical
components. The reason the DVM is instanced instead of copied into memory each time is that only
one version of the DVM in memory is needed and can be used and referenced by all applications.
Each app does not need to have its own copy of the DVM in memory as that would be very
inefficient, and the DVM is all about efficiency!


The DVM implements your Java language instructions, along with your application UI design
guidelines (in the form of Java objects) that you defined using XML markup, combines these with
external new media assets (images, audio, video, 3D,and so forth), and translates this infrastructure
into optimized, low-level, binary code. These low-level instructions get placed into the Android
hardware device memory, and are submitted to the OS process or “thread” manager, which then
takes these low-level instructions out of memory and runs them through the device CPU (processor)
for real-time processing, thereby “running” your Android application for your end-user.


So, what is the advantage of this DVM? The use of a DVM will allow more applications to run within
a somewhat limited memory space (1GB to 2GB) and with the slower (1GHz to 2GHz) processor
speed found in today’s consumer electronic devices. The DVM also protects all of the other launched
(active in memory) processes from interfering with each other. In this way, a crash of one application
will not bring down the entire Android operating system. This is a major advantage, because other
developers’ Android apps cannot cause your app to crash, or heaven forbid vice-versa.


The other major advantage of the DVM runtime environment is that you don’t have to create a
different version of your app for every CPU brand and manufacturer in the marketplace. As we all
know, Intel, AMD, and nVidia are competing in this mobile space, as are the ARM processor and
the Cortex processor, among others. By having one version of Java bytecode in your DEX file and
a runtime inside of the Android OS that turns this into binary machine language that is compatible
with the CPU architecture in any given Android device, our Android development work process is
simplified by an order of magnitude (or more, if more than ten different CPUs exist).


Android Runtimes: The Android RunTime VM


As of Android OS version 4.4, there is a brand new runtime called Android RunTime (ART). I will give
you an overview of ART in this section just so that you know about the very latest “under-the-hood”
developments in the Android OS. This is one of the cool things that you will learn in this book that will
allow you to “show off” your Android development knowledge to those that you wish to impress.

Free download pdf