Introduction to Android Platform and Android Development Environment

The Android Platform

The Android Platform is a software stack for Mobile Devices consisting of OS Kernel, System Libraries, Application Frameworks and Key Applications.

Android provides SDK for creating Applications. Android SDK consists of libraries, development tools and lots of documentation.

The Android Architecture

Android architecture consists of different layers like Linux Kernel, Libraries, Android RunTime, Application Framework. All of these layers will be used to develop Android Applications.

android Architecture

Linux Kernel

It’s the lowest layer of Android. It provides Android specific generic operating system services like security, memory and process management, File and Network Input/Output.

Android has a customized Linux kernel that is specific to Android. It provides power management, memory sharing and management (due to less memory constraints of mobile devices). Inter-process communication is allowed wherein it allows several processes to communicate among themselves in a sophisticated manner.

Device drivers needs to be plugged in, so that Android software can communicate with wide range of hardware devices like memory, radio, camera etc.

System Libraries

These are written in C/C++. Hence they are called native libraries. Android has its own C library. These system C libraries handle lot of core performance sensitive activities like rendering the images, updating the pages.

System C library is also called as BIONIC LIBC. It implements standard system calls which does things like process and thread creation, mathematical computations, memory allocation and much more.

Surface manager

It updates the display

Media Framework

To play audio/video

Webkit

For rendering and displaying web pages.

OpenGL

Performs and plays high end graphics.

SQLite

Perform in memory relational database.

Android RunTime

It supports writing and running android applications. Two main components are Core Java Libraries and Dalvik Virtual Machine.

Core Java Libraries 

The Android application is written in Java programming language. So Android makes available a number of Java libraries.

The Core Java library is made up of basic Java classes like Java.*, Javax.*

Android packages that are specific to the application life cycle are android.*

Internet/Web Services packages are org.*

Unit Testing packages are JUnit.*

Dalvik Virtual Machine

Applications are executed by the Dalvik Virtual Machine (DVM). Typical workflow is

  1. Application is written in Java
  2. Java Compiler compiles the application to multiple Java Byte code file.
  3. A tool called DX will convert the Java Byte Code file to a single DX Byte code file. (The file will have .dex extension. For e.g., classes.dex)
  4. This dex file is packaged with other application resources and installed on to the devices.
  5. When the user finally launches the application the Dalvik Virtual Machine executes the dex byte code file.

The reason for doing all of this or using the Dalvik Virtual Machine is DVM is designed to run in resource constrained environment which is a typical scenario for mobile devices. Resource constrained because when compared to desktop PCs/Laptops, the mobile devices have

  1. Slower CPU
  2. Less RAM
  3. Limited Batter

Application Framework Layer

It has many reusable software components.

View System

Contains many common graphical items like buttons, icons that many applications include in their user interface.

Package Manager

Keeps track of all the packages that are currently installed on the device.

Window Manager

Manages the many windows that comprises the application.

AndroidWindow

Resource Manager

Manages non compiled resources like strings, graphics and layout files.

Activity Manager

Activity means it corresponds to single user interface screen.

An App will have multiple activity through which the user needs to navigate.

Content Providers

Content Providers are essentially databases that allows the application to store and share the structured information. Contact Content Providers stores the mobile numbers which is used by the dialler to dial the number. These are used for inter application data sharing.

Location Manager

It allows the App to access the location information and movement information. For e.g., GPS Systems.

Notification Manager

It allows applications to place the notification icons on the status bar when important events occur. For e.g., if I’m browsing and in between if I receive a message, then that SMS message icon is displayed in the notification bar. Notification bar will be at the very top row (in the battery row).

Application Layer

It contains standard applications like Home Screen, Contacts, Phone Dialer, Browser, Email reader and others. The better part is none of these apps are hard coded into Android. You can substitute these applications with better applications or any 3rd party applications.

The Android Development Environment

Android Studio is the official IDE for Android application development, based on IntelliJ IDEA. On top of the capabilities you expect from IntelliJ, Android Studio offers:

  • Intelligent code editor
  • Multi-screen app development, Rich layout editor with support for drag and drop theme editing
  • Virtual devices for all shapes and sizes
  • Code templates to help you build common app features and GitHub integration
  • lint tools to catch performance, usability, version compatibility, and other problems
  • Flexible Gradle-based build system
  • Build variants and multiple apk file generation
  • ProGuard and app-signing capabilities
  • Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine

Virtual Device

The Android Emulator is called Virtual Device. Following are the Pros of Android Emulator

  1. Doesn’t require an actual device.
  2. Hardware characteristics can be easily reconfigured like setting the amount of memory.

Following are the Cons of Android Emulator

  1. Its very slow.
  2. Some features are not well supported like Bluetooth or USB connections are not supported properly.
  3. Performance/User Experience can be misleading.

Debugger

Tool for examining the internal state of a running application.

DDMS
Android Studio includes a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more.

Reading and Writing Logs
The Android logging system provides a mechanism for collecting and viewing system debug output.

Logcat dumps a log of system messages, which include things such as stack traces when the emulator throws an error and messages that you have written from your application by using the Log class. You can run LogCat through ADB or from DDMS, which allows you to read the messages in real time.

Improving Your Code with lint
In addition to testing that your Android application meets its functional requirements, it’s important to ensure that your code has no structural problems.

Poorly structured code can impact the reliability and efficiency of your Android apps and make your code harder to maintain. For example, if your XML resource files contain unused namespaces, this takes up space and incurs unnecessary processing.

Other structural issues, such as use of deprecated elements or API calls that are not supported by the target API versions, might lead to code failing to run correctly

Profiling with Traceview and dmtracedump
Traceview is a graphical viewer for execution logs that you create by using the Debug class to log tracing information in your code.

Traceview can help you debug your application and profile its performance.

dmtracedump is a tool that gives you an alternate way of generating graphical call-stack diagrams from trace log files.

The tool uses the Graphviz Dot utility to create the graphical output, so you need to install Graphviz before running dmtracedump.

The dmtracedump tool generates the call stack data as a tree diagram, with each call represented as a node. It shows call flow (from parent node to child nodes) using arrows.

Analyzing UI Performance with Systrace
While developing your application, you should check that user interactions are buttery smooth, running at a consistent 60 frames per second. If something goes wrong, and a frame gets dropped, the first step in fixing the problem is understanding what the system is doing.

The Systrace tool allows you to collect and inspect timing information across an entire Android device, which is called a trace. It shows where time and CPU cycles are being spent, displaying what each thread and process is doing at any given time. It also inpects the captured tracing information to highlight problems that it observes, from list item recycling to rendering content, and provide recommendations about how to fix them.

Leave a Reply

Your email address will not be published. Required fields are marked *