The Android SDK
Discipline of IT
James Cook University
This presentation focuses on…
1. The Android SDK (Setup)
2. Java Programming
3. Basic Android Programming
2
Android is owned by Google, and Google is a part of OHA
The Android OS is purpose-built for mobile devices
“…accelerate innovation in mobile and offer consumers a
richer, less expensive, and better mobile experience…”
Android is a complete, free, and open source mobile platform…
Java vs Dalvik
Java vs Dalvik
•Your java source code gets compiled twice to run on an Android
mobile device…
• Why? Java tends to change – but the bytecode
spec does not…
•It’s possible to write Android apps in a variety of programming
languages
• Android NDK (C/C++)
• ASE http://code.google.com/p/android-scripting/
A brief history of Android
– 2005: Google buys Android, Inc.
– 2007: Open Handset Alliance announced and Android is released as
open source
– 2008: Android SDK 1.0 released
– 2009: Huge numbers of Android-powered devices are sold
– 2012/2013: Android SDK version 4.1 – 4.3
– 2013: Android SDK version 4.4 (“kitkat”)
– 2014: Android SDK version 5 (“lollipop”)
• Note: replaced Dalvik with Android Runtime (ART)
– 2015: Android SDK version 6 (“Marshmallow”)
Setting up the Android SDK and Android Studio
• Android Studio is a powerful, open source, customizable
IDE
• Provided WYSIWYG GUI designer
• Sophisticated debugging support
• Android SDK is a collection of Command-line tools
• Currently runs on Java (1.7 or higher)
8
Android Studio offers simple Installation
• Android Studio is a bundled installer
• It will install the Android SDK and the most recent
Android Platform (API 22)
• It is then a good idea to select additional
platforms (e.g. API 19)
9
Setting up the Android SDK Manager
• This tool is used to add particular versions of the SDK to
your computer
• It also provides various extras like USB driver
support, emulator images, Google APIs, …
It’s worth checking for SDK updates
on a regular basis!
10
Setting up the AVD Manager
• This tool is used to create configurations for the emulator
11
Useful features
• Android Layout Editor – the WYSIWYG GUI designer
• GUIs in Android are specified using XML
• The XAML is automatically converted into Java
code for you
• Android Manifest Editor
• Graphical view of a projects configuration file
• Lint
• Offers advice to the programmer about
improving their code!
12
Useful features
• adb
• Useful for obtaining shell access to an
emulator or real device – handy for removing
apps (http://developer.android.com/tools/help/adb.html)
• DDMS (the android SDK “monitor” tool)
• A server that monitors debug/log messages
from the emulator or a real device
13
Other useful Android SDK commands
• Monkey
• Supports automatic UI event testing
• Sqlite3
• A light-weight database tool
• Keytool
• Used to generate signing certificates for Apps
• Note: Eclipse ADT automatically does this for
projects (in debug mode)
14
Java programming
• AndroidJava = Java - Swing + AndroidSDK
• The traditional Java GUI system is replaced
• But Android’s Java is mostly standard Java
15
Primitive data types
16
Classes and objects
• Android Java looks very similar to standard Java:
• final, static, public, private, protected
• Member fields/methods
• Inheritance
• Late binding / polymorphism
• Interfaces, abstract classes
• Exceptions
• Primitives are autoboxed as wrapper classes
• Java has automatic garbage collection
• No delete operator
17
Beware
• Avoid using:
• finalize() method
• clone() method
• Android does not support them
18
Correctly overriding equals() for your own classes
19
Java Collection API
• List: ArrayList, LinkedList
• Map: HashMap, TreeMap
• These are generic classes
20
Collections and thread safety
• Java and Android are multi-threaded
• The standard Java Thread API can be used
• Synchronization strategies apply!
• Useful point:
• Vector, Hashtable are thread safe!
21
Java packages
• Classes are grouped into packages
• Even your own classes:
• So that’s why when you create a new Android
Project it requires a package!
22
Inner classes and event callbacks
• This is the way Android events are handled in Java code
23
Anonymous inner classes are also common
24
Good design
• This code also demonstrates a way to separate the
application logic / model code from the GUI code
• We will be exploring good design more in this subject:
• Delegation
• Model-View-Controller
• Modularity
25