This is my first article ever on code project. I decided to participate in Android Tutorial Contest (Article #1) as I thought this is a good place to start. I don’t have much experience in android development and so to learn more I decided to write an introductory article because what better way to learn something that trying to explain it to someone else.
What is Android?
Android is an open source mobile operating system for a wide variety of devices and different form factor. The purpose of Android is to promote openness in the mobile world. Since it originated many companies have invested in Android. Currently, the Android open source project is led by Google and the majority of the Android software is licensed with Apache 2.0.
Android’s user interface is based on direct manipulation. According to Wikipedia:
“Direct manipulation is a human–computer interaction style which involves continuous representation of objects of interest and rapid, reversible, and incremental actions and feedback.”
To explain it more clearly, Android uses touch inputs that correspond to real-world actions (e.g. swiping and tapping). The response to the input is immediate and provides haptic feedback, usually by using the vibration capabilities.
Moreover, most Android powered devices have built-in sensors that measure motion, orientation and various environmental conditions; the device is equipped accelerometers, gyroscopes and proximity sensors. These are used to respond to additional user actions. For example, a game can allow the user to steer the main character through a maze.
The latest major release of Android is version 4.4 (code name: Kitkat). Starting for version 1.5, Android versions are code named after some sweet and released in alphabetical order.
Android Versioning History
Ice Cream Sandwich
Google provides major upgrades, to Android every six to nine months. However, the updates often arrive month from the official release. This is mainly due to two reasons. The first reason is the variation in hardware of Android devices and hence each upgrade must be specifically tailored. The second reason is that manufacturers customize Android with their own interface and applications; these customizations need to be reapplied with each new release causing additional delays.
This has made porting Android to a specific device a time and resource consuming process. Manufactures prioritize their devices leaving older devices behind. Hence, older devices are not updated regardless of the phone's capability to run the update.
What else is out there?
There are a number of alternative mobile operating systems. The most common ones are IOS from Apple, Blackberry from Blackberry and Windows Phone from Microsoft. All these three are closed source and proprietary, which sets Android apart being free and open source.
Regarding features and functionality, it is my opinion that, all mobile operating systems are pretty much the same. You will find debates and comparisons why one OS is superior but at the end of the end it is a matter of a personal preference.
Initially, the user may find some features visually appealing in one OS over the other e.g. live wallpapers but after a while the user will stop noticing these cosmetic details. All they care about are their apps. Hence, in today’s mobile world, apps became more important that the operating system they sit on.
The biggest market shares are for IOS and Android. However, up till now, Apple limits itself to selling premium devices while Android runs on different forms and factors, from low end devices to premium ones.
This has constrained Apple’s market share while allowed Android to tap into the market of the billions of users who are switching from their basis phones into a smartphone. Currently, Android has the biggest market share followed by IOS, while Windows Phone lags behind at a market share of only 3%.
Not a Mobile Developer? Not a Developer...
This is the title of a great talk by Dino Esposito at the Norwegian Developer’s Conference (NDC) 2012. It talks about how mobile became the primary focus of development in only a few years. I suggest you watch it if you haven’t already.
Today, any decent developer cannot ignore development for mobile devices. More and more users are becoming more attached to their smartphones. The global smartphone audience reached 1.75 Billion in 2014. This is a huge user base that cannot be ignored. People want information at their fingertips anywhere in the world. It is clear that you need to add mobile development to your portfolio. The question is why Android in particular? Why not IOS for instance?
This can be summed in in the following list of reasons:
- Android holds 61.9% of the U.S. market share, 82.7% market share in China and 73.3% across Europe in countries including the UK, France, Germany Spain and Italy. This is a huge user base that you can target.
- Tons of community members have already taken interest in Android development; you, as a developer, will have access to a lot of materials (books, tutorials, videos, etc...). Also, many of the problems you will face, you will find lots of help because most likely someone else has already faced a similar problem.
- The Android market is stable and has proven successful. There is currently over one million apps on Google Play Store with over 25 Billion downloads. The users are always hungry for more apps.
- There is no restriction on what you can do. All kinds of apps are in demand whether it is social media apps, games or expense managers. Even, companies like SAP are now providing dashboarding solutions for mobile devices because they know this is the future. This means that you can leverage you existing application in an existing field and try to bring a new experience to the users onto their smartphones.
Android Architecture Stack
The following diagram shows Android Architecture. It consists of four main layers and each layer provides different services tothe layer above it.
The first layer and the most basic one is the kernel, the entire operating system builds on top of it. The latest version of android (Kitkat 4.4) is built on top of the Linux kernel 3.8
The kernel has two main jobs. The first job is to interact with the hardware and act as an abstraction layer between the hardware and other software. Hence, part of the kernel is device drivers (e.g Bluetooth, camera, Wifi, etc...). The second job is providing the core functionality of the operating system including memory management, process management, power management, networking and security.
The next layer is Android native libraries, they sit on top of the kernel and provide a core set of functionalities. Among the famous libraries are “OpenGL” used to render 2D and 3D content onto the screen, “SQLite” a database engine that handles data storage and “WebKit” the browser engine.
The Android runtime is a java virtual machine that is optimized for Android a.k.a. Dalvik Virtual Machine. Due to security considerations, all android applications run sandboxed in this virtual machine.
However, you don’t have to worry about slow performance because Android uses “Just-in-time (JIT) compilation”. Parts of the bytecode are compiled into faster machine-code on-the-fly, ‘just in time’ for execution in a process.
You might wonder, why not compile all application into machine code in the first place. When you compile into machine code, you are compiling for a specific CPU and cannot use it on a different architecture and so the app will need to be compiled for each available configuration out there. Google opted for the second choice where one version of app is available on the Play Store and use JIT compilation to improve performance.
Currently, Google is experimenting with an “Ahead-of-Time (AOT) compiler” where the app is compiled into native code upon installation. This will bring better performance and improved battery life (no need for a JIT compiler when running apps).
This layer provides the building blocks that your application interacts with. They also provide a number of services. This layer provides the tools each developer uses to develop Android apps. Among the important building blocks is:
-Activity manager: manages the lifecycle of the application.
-Content provider: manages data sharing between applications.
-Resource manager: manages the different resources within an application.
These are the apps you write or that come pre-installed. It is worth mentioning that the apps that come with Android (e.g. dialer, contact manager) don’t have access except to the same building blocks provided by the application framework. A developer can replace these apps with custom ones. This shows that the developer is practically limitless in what he can achieve with Android.
An Android application consists of a number of building blocks called components. The four building blocks (components) are activities, services, content providers and broadcast receivers. Some components depend on each other but each component has a distinct purpose and plays a specific role.
An activity is a single screen with a user interface. For example, the calendar app has one activity that shows the list of entries for today, another activity to add a new entry and another one to show the entire month. An app is then composed of a set of activities.
A service on the other hand runs in the background. It could be used to perform a long running or remote operation for example; the web browser might have a service to download files. Services do not have a user interface, as opposed to activities. Activities can start services and let them run.
Broadcast receivers are used to respond to system wide announcements (e.g. a broadcast announcing a low battery status). Broadcast receivers do not have a user interface, like services, but they can create a notification bar to alert the user.
Broadcast receiver allows you to register for system or application events and you are notified once this event happens. Broadcast receivers are generally used to capture certain events and then run a service to do some work based on that event.
Content providers manage the application shared data to allow other apps to query or modify your app shared data. Content providers allow you to centralize content in one place and have many different applications access it as needed. It behaves very much like a database where you can query, edit, add or delete content.
To sum up, something that a user can do needs an activity, a background process needs a service, receiving messages needs broadcast receiver and to store or retrieve data content providers are used.
A great feature of Android is that any app can start a component of another app. For example, many applications launch the camera to capture a photo. This has huge implications, the developer doesn’t need to reinvent the wheel each time; instead the developer can simply start the activity of another app. When the app complete the result is returned and ready for use.
Hopefully this article has given you sufficient information for you to get interested in Android development and explained to you briefly Android Arhcitecture and app compononents.
I hope you like the post, if you have any question please leave a comment.