Chapter 1
IN THIS CHAPTER
Your take on Android (depending on who you are)
A tour of Android technologies
Until the mid-2000s, the word “Android” stood for a mechanical humanlike creature — a rootin’ tootin’ officer of the law with built-in machine guns, or a hyperlogical space traveler who can do everything except speak using contractions. But in 2005, Google purchased Android, Inc. — a 22-month-old company creating software for mobile phones. That move changed everything.
In 2007, a group of 34 companies formed the Open Handset Alliance. The Alliance's task was (and still is) “to accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience.” The Alliance's primary project is Android — an open, free operating system based on the Linux operating system kernel.
HTC released the first commercially available Android phone near the end of 2008, but the public's awareness of Android and its potential didn't surface until early 2010. By the mid-2010s, the world had more than 400 Android device manufacturers with 500 mobile carriers using Android and 1.5 million Android activations each day (https://expandedramblings.com/index.php/android-statistics/
). By mid-2019, more than 2.5 billion active devices ran the Android operating system (https://venturebeat.com/2019/05/07/android-passes-2-5-billion-monthly-active-devices/
). (We know. By the time you read this book, the year 2019 is old news. That's okay.)
This chapter introduces Android. The chapter examines Android from a few different angles.
A consumer considers the mobile phone alternatives.
Possibility #1: No mobile phone.
Possibility #2: A feature phone — a mobile phone that's not a smartphone.
Disadvantages: Not as versatile as a smartphone. Not nearly as cool as a smartphone. Nowhere near as much fun as a smartphone.
There's no official rule defining the boundary between feature phones and smartphones. But generally, a feature phone is one with an inflexible menu of home-screen options. A feature phone's menu items relate mostly to traditional mobile phone functions, such as dialing, texting, and maybe some limited web surfing and gaming. In contrast, a smartphone's home screen provides access to the underlying file system and has icons, customizable skins, and many other features that used to be available only to general-purpose computer operating systems.
Don't write off feature phones. As late as March 2019, Counterpoint Research predicted that people will buy a billion feature phones between 2019 and 2022 (https://www.counterpointresearch.com/more-than-a-billion-feature-phones-to-be-sold-over-next-three-years/
). This fact may shock you if you live in a country where feature phones are passé. But in 2019, the worldwide feature phone continued to grow.
Possibility #3: An iPhone.
Possibility #4: An Ubuntu Touch phone, a Harmony OS phone, or some other non-Android, non-Apple smartphone.
Possibility #5: An Android phone.
https://www.knowband.com/blog/mobile-app/alternatives-for-publishing-android-app-on-google-play-store/
for alternative ideas).Android's advantages far outweigh the possible disadvantages. And you're reading a paragraph from Android Application Development All-in-One For Dummies, 3rd Edition, so you're likely to agree.
Having decided to go with an Android phone, the consumer asks, “Which phone?” And the salesperson says, “This phone comes with Android 10.” (If you read between the lines, what the salesperson really means is “This phone comes with Android 9, which will eventually be upgraded to Android 10, or so claims the vendor.”) So the consumer asks, “What are the differences among all the Android versions?”
Android comes with a few different notions of “version.” Android has platform numbers, API levels, codenames, and probably some other versioning schemes. (The acronym API stands for Application Programming Interface — a library full of prewritten programs available for use by a bunch of programmers. In this case, the “bunch” consists of all Android developers.)
To complicate matters, the versioning schemes don't increase in lockstep. For example, Android 8 (codenamed Oreo) has two API levels — levels 26 and 27. But Android 9 (codenamed Pie) has only one API level — level 28.
An Android version may have variations. For example, you can develop for plain old API Level 29 with an established set of features. To plain old API Level 29, you can add the Google APIs (thus adding Google Maps functionality) and still be using platform API Level 29. You can also add a special set with features tailored for a particular device manufacturer or a particular mobile service provider.
API levels 3 through 28 had tasty dessert codenames, and the names came in alphabetical order. For example, after Lollipop came Marshmallow; after Marshmallow came Nougat. Sad to say, the last-ever Android dessert codename was Pie, released in August 2018. About a year later, Google released a newer version simply named Android 10. The number 10 doesn't taste good the way lollipops and pies do.
Figure 1-1 has a summary of Android's API versions from 2008 to 2019.
A few notes on Figure 1-1 are in order:
Build.SERIAL
stands for the phone's serial number. So, you might be tempted to type Build.SERIAL in code that uses API level 9.0. But in API level 9.0, Build.SERIAL
doesn't help you get a phone's serial number. In API level 9.0, the value of Build.SERIAL
is "UNKNOWN"
.Since 2016, a new version of Android has come roughly once a year. Google released Nougat in 2016, Oreo in 2017, Pie in 2018, and the sugarless Android 10 in 2019. As a developer, your job is to balance portability with feature richness. When you create an app, you specify a minimum Android version. (You can read more about specifying a minimum version in Chapter 4 of this minibook.) The higher the version, the more features your app can have. But the higher the version, the fewer the devices that can run your app.
This book contains tips and tricks for striking a happy medium between whiz-bang features and universal use, and Google has some nifty tools to help you sort out the differences among Android versions. In Chapter 3 of this minibook, you use Android Studio to create your first app. During the app setup, a drop-down box gives you a choice of Android versions for your app. Beneath that drop-down box is an innocent-looking Help Me Choose link. If you click this link, you see a page with the title Android Platform/API Version Distribution. This interactive page lists several of the most recent Android versions along with the percentage of phones that can run each version. And, when you click one of the Android versions, the page provides information about that version's features.
Android is a multifaceted beast. When you develop for Android, you use many tool sets. This section gives you a brief rundown of those tool sets.
James Gosling from Sun Microsystems created the Java programming language in the mid-1990s. (Sun Microsystems has since been bought out by Oracle.) Java's meteoric rise in use came from the elegance of the language and the well-conceived platform architecture. After a brief blaze of glory with applets and the web, Java settled into being a solid, general-purpose language with special strength in servers and middleware.
In the meantime, Java was quietly seeping into embedded processors.
The trouble was, not everyone agreed about the fine points of Java's licensing terms. The Java language isn't quite the same animal as the Java software libraries, which in turn aren't the same as the Java Virtual Machine (the software that enables the running of Java programs). So, in marrying Java to Android, the founders of Android added an extra puzzle piece — the Dalvik Virtual Machine (see the “What is Dalvik” sidebar in Book 2, Chapter 3 for details). And instead of using the official Sun/Oracle Java libraries, Android used Harmony — an open-source Java implementation from the Apache Software Foundation. Several years and many lawsuits later, Google and Oracle were still at odds over the use of Java in Android phones.
Programmers always use one kind of software to develop other kinds of software. For several years, programmers had developed Android apps using software named Eclipse. In the meantime, a competing product named IntelliJ IDEA was growing in popularity. A group of engineers from Google and IntelliJ IDEA's parent company (JetBrains) cooperated to create a very lean version of IntelliJ IDEA. Simply put, they removed the features of IntelliJ IDEA that Android developers would never use. From this stripped-down version of IntelliJ IDEA, they created a customized product especially for Android programmers. At its annual developer conference in 2013, Google introduced Android Studio — the shiny new tool to help Android developers be more productive.
Also at the aforementioned 2013 developer conference, Google began the process of replacing Dalvik with a new virtual machine named Android Runtime, or ART. Programs ran faster under ART, plus they consumed less memory and less power, and they were easier to debug. The transition from Dalvik to ART was a first step in the separation of Android from Oracle's proprietary Java technologies. (For more information about the Dalvik Virtual Machine and ART, see Book 2, Chapter 3.)
While Android matured, new programming languages were making improvements on many of Java's long-standing features. Apple was developing Swift to replace the aging Objective-C language. With Swift and other such languages, developers had a natural way of controlling how values may change during the run of a program. Developers could easily extend existing functionality and create code to tame null values — values that expert Tony Hoare had dubbed a “billion-dollar mistake.” In newer languages, programmers used built-in features to write code in a functional style (a coding technique that expresses computational goals in the form of math functions) — a style that Book 2, Chapter 6 covers in detail.
JetBrains was developing one of these new languages. The language's name — Kotlin — came from the name of an island near St. Petersburg in Russia. Kotlin borrowed many of Java's features and improved on them in significant ways. At its annual developer conference in 2017, Google announced support for creating Android programs using Kotlin.
A year later, 35 percent of all Android programmers were using Kotlin. In 2019, Google officially dubbed Kotlin as the preferred language for Android app development.
Kotlin is fully compatible with Java. So, when you create an Android app, you can borrow pieces of programs written in Java and meld them seamlessly with your Kotlin code. Kotlin also integrates with JavaScript, so developers can write Kotlin programs that drive web pages. Behind the scenes, Kotlin plays nicely with Node.js — a widely used platform that runs on servers around the world. You can even translate Kotlin into native code — code that runs on Windows, macOS, Linux, and other operating systems.
Kotlin is deeply entrenched in the Android ecosystem and in other systems as well. If you already have some Kotlin programming experience, great! If not, you can find a fast-paced introduction to Kotlin in Book 2, Chapters 2 through 4. The time you invest in developing mobile Kotlin-based apps will continue to pay off for a long, long time.
If you find View Source among your web browser's options, you see a bunch of Hypertext Markup Language (HTML) tags that represent the coding for a web page. A tag is some text enclosed in angle brackets. The tag describes something about its neighboring content.
For example, to create boldface type on a web page, a web designer writes
<b>Look at this!</b>
The angle-bracketed b
tags turn boldface type on and off.
The M in HTML stands for Markup — a general term describing any extra text that annotates a document's content. When you annotate a document's content, you embed information about the document's content into the document itself. So, for example, in the line of code in the previous paragraph, the content is Look at this!
The markup (information about the content) consists of the tags <b>
and </b>
.
The HTML standard is an outgrowth of SGML (Standard Generalized Markup Language). SGML is an all-things-to-all-people technology for marking up documents for use by all kinds of computers running all kinds of software and sold by all kinds of vendors.
In the mid-1990s, a working group of the World Wide Web Consortium (W3C) began developing XML — the eXtensible Markup Language. The working group's goal was to create a subset of SGML for use in transmitting data over the Internet. The group succeeded. Today, XML is a well-established standard for encoding information of all kinds. Java is good for describing step-by-step instructions, and XML is good for describing the way things are (or should be). A Java program says, “Do this and then do that.” In contrast, an XML document says, “It's this way, and it's that way.” Android uses XML for two purposes:
To describe the app itself: Each Android app comes with an AndroidManifest.xml
file. This XML document describes features of the app. The operating system uses the AndroidManifest.xml
document's contents to manage the running of the app.
For example, an app's AndroidManifest.xml file contains the app's name and the name of the file containing the app’s icon. The XML file also lists the names of the app’s screens and tells the system what kinds of work each screen can perform.
For more information about the AndroidManifest.xml
file and about the use of XML to describe an app's data, see Chapter 4 of this minibook.
Concerning XML, there's bad news and good news. The bad news is, XML isn't always easy to compose. The good news is, automated software tools compose most of the world's XML code. The software on an Android programmer’s development computer composes much of an app's XML code. You often tweak the XML code, read part of the code for info from its source, make minor changes, and compose brief additions. But you hardly ever create XML documents from scratch.
An operating system is a big program that manages the overall running of a computer or device. Most operating systems are built in layers. An operating system's outer layers, such as the applications and the environment in which the user interacts with the applications, are usually right up there in the user's face. For example, both Windows and macOS have standard desktops (a paradigm for the interface the user sees, sort of like the physical desktop you use at work). From the desktop, the user launches programs, manages windows, and so on. When you’re working with Android, the desktop is represented by the Android Application Framework (shown in Figure 1-2).
An operating system's inner layers are (for the most part) invisible to the user. While the user plays Solitaire, the operating system juggles processes, manages files, keeps an eye on security, and generally does the kinds of things that the user shouldn't micromanage. Figure 1-2 shows the Android version of these inner layers as Libraries and the Android Runtime.
At the very deepest level of an operating system is the system's kernel. The kernel runs directly on the processor's hardware and does the low-level work required to make the processor run. In a truly layered system, higher layers accomplish work by making calls to lower layers. So an app with a specific hardware request sends the request (directly or indirectly) through the kernel.
The best-known, best-loved general-purpose operating systems are Microsoft Windows, Apple macOS (which is built on top of UNIX), and Linux (from various vendors). Windows and macOS are the properties of their respective companies. But Linux is open source. That's one of the reasons why the creators of Android based their platform on the Linux kernel. Openness is a good thing!
Figure 1-2 is a diagram of the Android operating system. If you'd like a ten-cent tour, read on.
Below the applications layer lies the Application Programming Interface (API) layer. Your Android programs make requests to pieces of code in this API layer. In fact, most of this book's chapters describe ways for you to use Android's API layer.
As an Android developer, you almost never deal with layers below the API layer. But just this once, you can take a quick peek at those three layers. Here goes …
As a developer, your most intimate contact with the Android operating system is through the command line, or the Linux shell. The shell uses commands, such as cd
to change to a folder, ls
to list a folder’s files and subfolders, rm
to delete files, and many others.
The Google Play Store has plenty of free terminal apps. A terminal app's interface is a plain text screen in which you type Linux shell commands. And with one of Android's developer tools, the Android Debug Bridge, you can issue shell commands to an Android device through your development computer. If you like getting your virtual hands dirty, the Linux shell is for you. (For a look at the Android Debug Bridge, see Chapter 2 of this minibook.)
The creation and selling of mobile phone apps is an enormous industry. The Google Play Store had 2.57 million apps at the end of 2019. By the time you read this book, the number 2.57 million will seem pathetically obsolete. With the marketing potential of alternatives such as the Amazon Appstore for Android and Samsung Galaxy Store, you have many distribution channels for your apps.
Anyone can post an app for approval on the Google Play Store. (The app doesn’t actually appear for download until Google reviews and approves it.) You can post free apps, paid apps, and programs with in-app billing. You can test an app with a select group of users before making your app available to everyone. You make a small one-time payment to register as an Android developer. Then you design apps, develop apps, and post apps for the general public.
Book 6 covers the business of posting apps on the Google Play Store and the Amazon Appstore for Android. You may not become a millionaire selling Android apps, but you'll definitely have fun trying.
34.231.180.210