Hello readers, today we are an Introduction to How Android Works. If you like this information, please share it with your friends. Give me a comment to improve my writing skills and subscribe by email for future updates.
Android development is a popular buzz in the Java programming world. It's Android, which keeps Java at the forefront of the last couple of years. Now, How important is it to understand or learn Android for Java programmers? Well, it depends on, if you like application development and wants to reach a mass, Android offers that opportunity to you. Millions of Android phones are available and they keep increasing, with pace, much higher than iPhone or iOS. What all this means is, it does make a lot of sense to learn Android programming for Java programmers, and this article is about that, but this is also one of the good reasons to learn Java programming. This tutorial will give you a basic idea of How Android works? not detailed but a good overview.
One distinct advantage Java programmers have over others is that Android API is much like Java API, though Android doesn't support all classes available in J2SE SDK, it supports critical ones.
Another advantage is that you can use the same tools as IDE like Eclipse or Android Studio if you are an IntellijIDEA fan to develop Android applications, Google provides an Eclipse plug-in for Android development.
In order to start with Android, you can start reading books or join an online course like The Complete Android Oreo Developer Course - Build 23 Apps! course by Rob Percival and Nick Walter on Udemy. It's a great hands-on course to learn Android in depth.
On the opposite, if you want to go for iOS development, a steep learning curve with Objective-C, Swift, and iOS SDK waits for you. I think it makes more sense for a C++ programmer to do Objective-C and iOS, than a Java Programmer. So the classic battle of Java vs C++ still continues with Smartphone application development. Anyway, let's come to the topic of How Android works internally.
How Android works
As I said Android uses Java for application development. So you can code your Android apps using Java API provided by Google, and it compiles them into class files. The similarity ends here, Android doesn't use Java Virtual machine (JVM) for executing class files, instead, it uses Dalvik virtual machine, which is not a true JVM and doesn't operate on Java bytecode.
In order to run on Dalvik Virtual machines, class files are further compiled into Dalvik Executable or DEX format. After conversion to DEX format, class files along with other resources are bundled into Android Package (APK) for distribution and installation into various devices.
The key thing to know is that Dalvik VM is based on a subset of the Apache Harmony Project for its core class library, which means it doesn't support all J2SE API. If you are using Eclipse IDE for coding Android Apps, then you don't need to worry much because it will help you with code completion.
So, now let's see
How does the Android Application run on a device?
If you are familiar with Linux and the concept of process, then it's easy to understand how android applications run. By default, Each Android application is assigned a unique user id by the Android operating system. After starting an android application, they run in their own process, inside their own virtual machine.
An android operating system manages the starting and shutting down of the application process, whenever required. This means each android application runs in isolation from others, but they can certainly request access to hardware and other system resources.
If you are familiar with mobile application development, maybe in J2ME, then you may know about permissions. So when an android application is installed or started, it requests the necessary permission required to connect to the internet, phone book, and other system resources. The user explicitly provides grants these permissions, or it may deny them.
All these permissions are defined in the manifest file of the Android application. Unlike the Java Manifest file, the Android manifest is an XML file, which lists all the components of apps, and settings for those components.
Four major components of Android application development are Activities, Services, Content Providers, and Broadcast Receivers. Activity is the most common of them, as it represents a single screen in Android Application. For example, in an Android Game, you can have multiple screens for login, high score, instructions, and game screen. Each of these screens represents different Activities inside your app.
Similar to Java, a good thing about Android is that it manages certain tasks on behalf of the developer, one of them is creating an activity object. Activities are managed by System, when you want to start an activity, you call the startActivity() method which takes an Intent object. In response to this call, System can either create a new activity object or reuse an existing one.
Just like Garbage collection in Java, which manages a critical task or reclaiming memory, Android manages the starting, stopping, creating, and destruction of apps by themselves. You may think it's restrictive, but it's not. Android provides life cycle events, which you can override to interact with this process.
That's all on How Android works. Android is definitely worth learning for Java programmers, as it uses Java, you can reuse your existing knowledge of Java programming techniques, design patterns, and best practices to code a good android app. Of course, you need to adapt some Android-specific things like, but those will come along.
Thanks for Reading!
If you learned at least one thing with this post, then share the post. There is no expert who can remain an expert without sharing their knowledge. So, keep sharing your knowledge with everyone.