Android is a software stack for mobile devices that includes an operating system, middleware and key applications. Android is written by Google and most of its source code is released under the Apache license. Version 1.0 of Android was released in September 2008 and the latest version is currently 6.0 Marshmallow powering smartphones and tablets.
There are over one billion active monthly Android users and Android has become the best-selling mobile platform worldwide surpassing iOS (iPhone/iPad), Microsoft, Blackberry and Nokia with ease.
- is an application framework which runs on the Linux kernel
- has an ART virtual machine, compatible with a large subset of Java, optimized for mobile devices
- has an integrated browser based on the open source WebKit engine
- provides optimized graphics powered by a custom 2D graphics library
- supports 3D graphics based on the OpenGL ES specification with optional hardware acceleration
- has SQLite (SQL database) for structured data storage
- supports media for common audio, video and image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
- supports GSM telephony
- supports Bluetooth, EDGE, 3G, and WiFi
- supports a camera, GPS, compass, and accelerometer
- finally, provides a rich and powerful development environment called Android Studio which includes an emulator, tools for debugging and memory and performance profiling.
Developing applications for Android
The following needs to be true for someone to be able to develop an Android application:
- The development computer needs to have a Java Development Kit (Oracles’s JDK or OpenJDK are both fine).
- The Android Software Development Kit needs to be installed.
- Android Studio needs to be installed.
- Finally, Android platforms and other components need to be added to the SDK. One example might be the Android 5.1 to target the latest devices or the 2.3.3 platform in order to be able to develop and test applications for older devices running Android 2.2.3.
Java is a powerful programming language which fully supports the object-oriented programming model. A good and free, if somewhat outdated, reference for the language is Thinking in Java (3rd edition) and is available at:
A quick start: Hello World
The first application to develop is HelloWorld which should simply display a nice “Hello World!” message when launched. The content of the HelloWorld project as generated by Android Studio should be explored (build.gradle, AndroidManifest.xml, src/main/res/, src/main/java/, etc.) and understood. The HelloWorld app can then be launched on a real Android device to check whether it is working properly.
In Android, apps generally have layouts (screens) which are defined in XML files in src/main/res/layout and behaviour is defined in Java in various files found in src/main/java.
The Activity lifecycle
An activity represents a single screen with a user interface. An application can have multiple independent activities.
When an app starts, Android chooses what activity to start initially based on information found in AndroidManifest.xml and ultimately calls its onCreate method. A programmer can specify what the activity should do when it starts by overriding this method.
What Time Is It?
The second application to develop is called What Time Is It. It displays one button which fills in the whole of its activity. When the button is clicked, the text shown in the button will be updated to the current date and time.
The way to do that is to add an Android button to the activity (this can be done by dragging a button to the layout and making it matching the width and height of its parent (i.e. the whole activity)), modify onCreate to make sure that the button shows the current date and time initially and setOnClickListener to update the label to the current date and time each time the button is pressed. The recommended way to do that is to use a Java inner class.