This presentation introduces the mobile operating
system
Android, including:
- Origins and history
- Software architecture
- Development Environment
- Developing Applications
- Android Inc. founded in 2003 by three individuals interested in
developing an advanced OS for digital cameras
- Sold to Google in 2005 where decision was made to market the
platform to handset makers and power it with the Linux kernel
- In 2007 the Open Handset Alliance was announced:
- Device makers: HTC, Samsung, Sony
- Wireless carriers: Sprint Nextel, T-Mobile
- Chipset makers: Qualcomm, Texas Instruments
Goal: Develop open standards for mobile devices
- In 2008, Google announced the Android Developer Challenge, a
contest to promote the OS
- $10 million in prizes
- 1800 developers submitted applications
- 10 apps selected for $275,000 prizes (one of which awarded
to UMD CS undergraduate)
- From 2008—present: numerous major releases of the OS,
alphabetically arranged with confection names
(e.g. 1.5 Cupcake, 1.6 Doughnut, 4.0 Ice Cream Sandwich
etc). Currently
at version 9 Pie.
- In 2014 Android One announced, targeting developing
world
- In 2015 Project Brillo announced as cut-down version of
Android for the Internet of Things
- In 2016 Google announced the Pixel, the first phone made by
Google
Android uses a multi-layered software architecture, with:
- Applications at the top
- An application framework supporting applications
- The runtime system and library running a version of the Java
Virtual Machine (JVM). Since 2015 based on OpenJDK.
- Libraries and APIs written in C
- Hardware interfaces
- The Linux kernel at the bottom
An
application (app) is composed of
screens. Screens are
composed of:
- A layout, written in XML, that defines the appearance of
the user interface
- An activity, written in Java, that defines what an app
does
Example: a layout might include a
button, described in XML,
while Java code describes what happens when the button is pressed.
Activities comprise the
application logic, which manages data
and controls user navigation. It uses the non-GUI parts of the JVM
specification.
Applications use a build tool called
Gradle, which uses Groovy
as its scripting language.
Up till Android 5.0, a Google implementation of the JVM
called
Dalvik was used for the application logic.
In December 2015, Google announced that the next version of Android
would switch to a Java implementation based on
OpenJDK.
In 2010, Oracle sued Google over the use of Java, arguing that Oracle
held the copyright to the Java APIs.
- In 2012 a district court
judge ruled that the Java API is not copyrightable.
- In 2014 an appeals court reversed the copyrightability
finding
- In 2016 a new trial ruled that Google's implementation of Java
APIs was fair use.
- Oracle appealed in October 2016
- Appeals court rules in March 2018 that Google's reuse of the
APIs was not fair use, and that lower court must determine
damages
- In early 2019 Google appeals to the U.S. Supreme Court
- In late 2019 the court
agrees to review the case
- In April 2021, the Supreme Court ruled in a 6–2 decision
that Google's use of the Java APIs fell within the four
factors of fair use, bypassing the question of the
copyrightability of the APIs.
The official IDE (integrated development environment) for Android
is
Android
Studio. Features:
- Built on IntelliJ, an environment
like NetBeans, with advanced code completion and
refactoring capability
- Fast Android device emulator (also allows testing on actual
devices)
- Flexible build system (using Gradle) with version
control (e.g. GitHub)
- Project and code templates
- Unit testing with JUnit 4
- Bundled with Android SDK (Standard Development Kit) tools
(e.g. debugger, libraries, emulator, docs, tutorials)
The instructions below are for installing and using Android Studio on
your own machine. Note: You can also install Android Studio on your
personal UMD disk space and run it on the development machines in
Heller Hall 314.
- Go to the Android
Studio Website and download the package for your platform (Linux, Windows,
Mac) to an appropriate location on your machine
- Follow the instructions for unpacking and launching the IDE
- Follow the Setup Wizard to set locations and components (can
take a few minutes)
- When finished, you should see:
To begin, click on
Create New Project.
You will be asked to select a project template.
An
activity is Java code that defines what an application does.
For now, choose an "empty" activity:
`
After providing a name and location of your project, you will be asked
to select the target devices for your app (see image below).
- The lower the SDK API's version number, the more devices will be
compatible with your app
- The higher the SDK API's version number, the more OS features
will be available
An
activity is Java code that defines what an application does.
For now, choose an "empty" activity:
When an activity is created, an activity name and associated layout
name are chosen.
For now, choose the defaults:
After dismissing a window offering the "tip of the day," you will see
the following layout of the IDE workspace.
Note the similarity to NetBeans: project navigation on the left, and
file contents on the right.
Below we see the Java class
MainActivity displayed. It refers to
the layout expressed by
activity_main.xml.
There are two views of the application's layout:
- Design view: a palette of "widgets" (GUI components) are
available for dragging and dropping into a design area
- Code view: the XML code is displayed next to a preview of
the application's appearance
After clicking on the
activity_main.xml tab, the layout is
displayed.
Below we see the design view of a default layout, obtained by clicking
Design in the upper right:
Below we see the text view of a default layout, obtained by clicking
Code in the upper right.
Generally, the code view gives one more control over aspects of the
layout than the design view.
Applications can be run either by connecting an actual Android device
to your system, or running the
Android Emulator
(also
Android Virtual Device, or AVD), which recreates
the exact hardware environment of an Android device.
In either case, click
Run on Android Studio's menu bar and
choose
Run 'app' as shown below.
Note the field just under the menu bar that contains
"
Nexus 6 API 25". This indicates that the app will be run on a
virtual device emulating a Nexus 6 whose Android API level is 25.
Virtual devices are described below.
The procedure to connect an actual device (an Android phone or
tablet) to a machine running Android Studio depends on the
machine.
- Go to the
Android Studio User Guide
- Select Build and run your app > Run apps on a
hardware device > Overview
- Follow the instructions for your machine's operating system
If you have successfully connected a device, it will appear in the device
drop-down as shown below.
Here an actual LG device has been connected to the computer and
selected from the drop-down. Now when the app is run the LG device will
be used.
If no physical devices are connected,
Android Studio will detect this, and you will need to create a
new
virtual device, or
emulator.
This requires two top-level steps:
- Select the hardware to be emulated
- Install a system image for the emulator
Start by clicking
Create New Virtual Device.
Select the
Phone category and a suitable device before
clicking
Next.
When no system image is detected, Android Studio will offer the
opportunity to download one, as shown below.
Click
Download next to a chosen image. You will be required to accept a
license agreement.
The system image is a tool in the Android SDK. Downloading and
installing may take a few minutes:
After downloading and installing, the system image can be selected.
Note that the API level of the system image is the API level of the
virtual machine implemented by the image:
- This is not to be confused with API
level you choose when you create a new app, but
- The API level of the emulator should be at least as high as the API
level of any app you intend to run on the emulator
Once the system image is selected, click
Next.
If successful, you will see a screen like that
below. Click
Finish.
Now select the virtual device you just created and click
OK.
This will launch the emulator.
Note that once you create an emulator, Android Studio will retain it
until you delete it.
The emulator is a full virtual implementation of Android running on a
device.
- Linux users: When you try to run an emulator you may get
this message: "/dev/kvm permission denied". This has to
do with kernel optimizations Linux uses to enhance emulator
performance. See This Forum for how to fix this.
It is not a
simulator (as with iPhone), which runs natively on
Macs.
The Android emulator is therefore slower, but it is richer and more
realistic than a simulator.
Here is a rendering of the emulator's interface, along with its control
panel:
To those with Android devices, the emulator interface is
familiar. Below is the screen after swiping to the right.
Swiping can be performed with the mouse, or, if your machine has a
touch-sensitive screen, by swiping just as you would on a phone.
Below is the app screen, obtained by swiping up on the home screen.
Note that
My Application appears at the top.
Here is the result of clicking (touching)
My Application.