Android Development

SYLLABUS
10 Sections
Introduction

1Introduction

In today’s world it would be hard to find someone who hasn’t heard of android. Do you have a killer app idea that you think is going to change the world? With around 2 billion monthly users worldwide it is an interesting and one of the major platform to develop apps for.

As this chart points out, it is a lucrative career choice even if you are working for somebody. Source.

Bonsai Developer Rates for Android Development

In this course you are going to learn the basics of developing apps for android. We will help you through each steps, right from setting up to publishing your app to the play store. The initial sections will guide you with resources on UI, look and feel of your apps and the later ones would be more about the core stuff. So if you’re ready to explore the wonderful world of android, let’s begin!

Prerequisites

2Prerequisites

Core Java

Java is the primary language used for developing android apps. Core java concepts should be very clear before diving into android development. Concepts like method overriding, inheritance, interfaces, and anonymous inner classes are commonly used in android development.

XML

XML or extensible markup language is used mostly to define UI layouts for android apps. It is also used to define some drawable shapes and menu items. Basic knowledge of XML is sufficient. W3Schools has a good reference guide.

Design Patterns

Not really a prerequisite, but knowledge of design patterns goes a long way in developing complex solutions. You may want to familiarize yourself with some common design patterns.

Setting Up First App

5Setting Up First App

IDE

An IDE or Integrated Development Environment is a software to run and execute your code. It has a lot of features which make development faster like code completion, organizing your project, searching for resources in your project, debugging your code etc. It can also be extended by installing plugins. For example, there is a plugin called key promoter which helps you learn keyboard shortcuts for the IDE by showing a modal window with the shortcut when you do an action/sequence of actions 3 times via mouse. For Android development the de facto IDE is Android Studio. It used to be eclipse previously but Google is not supporting it anymore. Android studio is a customized version of Intellij Idea by Jetbrains . Below is a photo of the Android Studio interface.

Android Studio interface
Android SDK

Android SDK (software development kit) is the set of libraries and resources (documentation, images, emulator etc ) that are required for development of application. A library is a collection of useful code which can be shared across easily. Imagine someone has written some code to perform some mathematical calculation. If they want to share their code to others, the easiest way would be to bundle it as a library and share.Android SDK comes bundled with android studio but can be downloaded separately and configured along.

Google provides different set of libraries and resources for different versions of the Android OS. All the resources can be updated within Android studio. You generally don’t have to worry about different versions because it is backwards compatible most of the times

Setting Up Your First App

After setting up and running the IDE, you’d want to try and run a basic android app. Fortunately, Android Studio has plenty of samples that you can easily import and run.

Running the App on Emulator

Once you import a sample you can think about running it. There are two ways that you can run your application: an emulator or a real device.

An emulator is a software application designed to mimic the behavior of a real device. It’s very useful in testing because you don’t need to buy an actual device. You can emulate different OS versions, screen sizes, display densities, some hardware features. It gives you look and feel of an actual phone/Tab on your PC or Mac.

Since Android is an open source operating system adopted worldwide and used in devices of varying features, it’s hard to test compatibility. This is where the emulator comes handy. Having said that, some features like NFC, Bluetooth cannot be emulated and you will need to use real devices for that. Also it is advisable to run production apps on real devices before releasing.

Android SDK comes bundled with default emulator image for a specific OS version. You can download and install different emulator images through Android Studio as well. The emulator images are called AVDs or Android virtual devices.

There are also some third party emulators available that you can use to run and test your apps. For example, there is GenyMotion, BlueStacks, and remix OS emulators.

Once you have set up an AVD, you can then proceed to run your application.

Android Emulator
Running on Real Devices

When you want to run you app on a real device, you would need a compatible device connected to your PC via USB. You would first need to install manufacturer provided driver software for that model installed on your PC. A driver is a piece of software that interfaces with a device’s hardware and a computer.

Installing drivers for different phone models is slightly different depending on the manufacturer and the model number. But it is a very similar process. Here is an example for Samsung devices. Once that is done, your device shows up as a runnable option when you press run button on Android Studio.

Android Studio device list

As you can see in the picture, my Xperia Z3 device shows up after I have configured it.

Project Configuration, Screens & Basic Layouts

16Project Configuration, Screens & Basic Layouts

Android Studio Sections

Now that we have setup Android Studio and ran our first app, we need to understand different components of the project and different sections of Android Studio.

The “Meet Android Studio” in the Android Studio documentation resource link below explains the different sections/windows and components of Android Studio very well. Also I have given an excerpt from it for an overview.

Android Studio UI Overview
  1. The toolbar lets you carry out a wide range of actions, including running your app and launching Android tools.
  2. The navigation bar helps you navigate through your project and open files for editing. It provides a more compact view of the structure visible in the Project window.
  3. The editor window is where you create and modify code. Depending on the current file type, the editor can change. For example, when viewing a layout file, the editor displays the Layout Editor.
  4. The tool window bar runs around the outside of the IDE window and contains the buttons that allow you to expand or collapse individual tool windows.
  5. The tool windows give you access to specific tasks like project management, search, version control, and more. You can expand them and collapse them.
  6. The status bar displays the status of your project and the IDE itself, as well as any warnings or messages.
Project Structure

There are different files+folders and resources that make a complete android application. It is essential to understand the different components that make up the entire project.

Screens

If you have used any GUI (Graphical User Interface) application, it is easy to recognize that it is made up of different screens. Android is no different. Your app can have different screens and they are called Activities in Android. Any activity in Android is basically a java class. Just like in Java where you have a main method to start your application, you have to define an Activity/Screen which will pop up when you start the app. This configuration can be done in the manifest xml file that you briefly saw in the previous section.

Basic Layouts

As you must have seen in the video of previous section, a layout UI needs to be defined for an Activity such that it displays some UI components. These UI components (Buttons, Edit texts controls, Image holders, Scrollable lists etc) can be defined either programmatically in java code or throughout layout XML files. Mostly, layout XML files are preferred because they are easy to configure and maintain. Also Android Studio has a visual drag and drop editor that can be used to define the UI for these xml files.

More UI Components, User Interaction & Screen Navigation

10More UI Components, User Interaction & Screen Navigation

Aggregate UI components

Simple UI components/widgets like TextView, Buttons, Radio Buttons etc can only display limited amount of UI at a time. For example if you want to display a scrolling list of text, you can’t create 10 or 100 different TextViews in your layout. In these cases you need UI components that can show aggregate data.

There are different UI views that can show aggregate data in android like

  1. ListView (Used to show data in vertical scrollable list)
  2. GridView (Used to show data in grids)
  3. RecyclerView

RecyclerView deserves separate explanation because that is a UI component that show aggregate data in vertical/horizontal list, square/staggered grids. It is extensive in such a way that it can show data in any style that you want. ListView and GridView are mostly obsolete now. Here is a great video series to help you better understand.

Images

Displaying images is one of the most common things that any android app does. Android provides a couple of UI widgets for displaying widgets and handling them.

User Interaction

To do some useful work the user need to interact with UI components. There are different ways how that could be done. E.g. tapping on the screen once, long pressing the finger the screen. Also some gestures like swiping left/right, pinch actions could be used. Each UI component has its own way of handling user interaction.

Screen Navigation

As we know that an app is composed of multiple Activities/Screens, we need to know how to navigate between them and the semantics around it. We also need to know the semantics of how to handle going back to previous screen.

Using Dialogs & Saving Data

7Using Dialogs & Saving Data

Dialogs

Dialogs (sometimes called modal windows) are used when there is immediate interaction needed with the user. The dialogs stop the user’s interaction from any other UI component till any action is taken on it. Most of the times they are used to alert user of something/get confirmation or used to get input without which the app cannot proceed further. An example would be a “Discard draft?” popup message.

Android Modal Window example
Saving data

For a good user experience we need to save regularly needed user data in our app. For e.g. Facebook app saves your login info so that you don’t have to login every time when you open their app.

Saving Data in Shared Preferences

Shared preferences is a provision given by the android SDK to store key value pairs in your app. As the name suggests, it is mainly used for storing small stuff like user preferences and settings.

Saving Data in Files

Saving data in files is another way to save user data for your app. This is mostly used when you have to store considerable amount of textual data. E.g. a note taking app

Saving Data in SQLite Databases

For saving relational/complex data in your apps, you can use Sqlite database. Sqlite is a tiny database that comes pre-packaged with the android OS. E.g. a contacts app that needs to save and display different contact details of multiple users.

Location & Maps

5Location & Maps

Location

Almost all the Android phones have an ability to get your current location. A lot of apps use this feature to give a better user experience. For e.g. navigation apps like Google maps use your location information to help you navigate from one location to another. Dating apps use this feature to find other users near you. As an android developer it is important to know how to access user location so that it could be used to give them a better experience or integrate with your service.

Maps

I believe that mapping technology along with gps has revolutionised travel. Google maps provide you with navigation, mapping, live traffic etc. As a developer you can leverage these services google provides in your own application. Google provides services for geocoding (converting location into an address) maps, navigation etc. to developers as well.

You can embed Google maps in your app or integrate with other services as you need. For example in a taxi app like Uber you can show where the driver currently located on a map with the help of these services.

Loading Websites

3Loading Websites

Loading Websites

Android SDK has a nifty configurable UI widget where in you can load websites within the app itself. The widget is called WebView. WebView is a UI widget just like any other UI view (Button/ TextView etc.) which can be placed or sized however you want in your layout. It is like an embedded mini browser in your app that can load any website you want

Connecting to the Internet

Perhaps the most frequent architecture that a lot of companies follow is that they have a web service and use an app/website as a front end. Take an example of taxi app like Uber. They have an app for making booking, payments, cancellations etc. and a backend web service which facilitates all of this. The app programmatically connects to their web service through the internet and exchanges data to and fro as required.

There are some free to use web services that your application can use to display information. For example, Open Weather API is a web service that provides data for you to use.

There are some libraries that allow you to connect to the internet and use web services. The most popular one and widely used library for Android is Retrofit. Retrofit is an open source and easy to use library.
The following resource will help you set it up and show how to use it

Uploading To Google Play Store

4Uploading To Google Play Store

Google Developer Account

So once you have created your own app, how would people get it or how would they buy it? You would need to upload your app onto Google Play Store. Google play store is a marketplace for android apps. Almost all of the android phones have it preinstalled from where they can download and install app.

To be able to upload apps on the play store, you need to have a developer account. It is a paid account and it costs 25$ as a onetime fee.

Signing and Creating the App Install File

In order to upload an app to the play store, you need its installable file. This file is of the format .apk. All of your code and resources (images, fonts etc.) are bundled into this file. In order for Google to accept your app submission, it needs to be a signed .apk file. In short, signing is a process in which your signature (which is a key or a sort of password) is embedded inside the .apk file so that Google knows it is genuine and has come from you.

Uploading Your App on the Play Store

The final step is to actually go the Google play developer console and upload the app. Before uploading, you have to create a listing for your app on the console. You need to fill in relevant details like the app’s name, description etc. and upload some screenshots of your app. The complete process is explained here.

Tips, Best Practices, Libraries & Community

5Tips, Best Practices, Libraries & Community

Tips

There are a lot of tips for beginners in Android development. Not all of them will be applicable for you. Honestly it takes practice and trying out a lot of different things to see what works for you and what does not. Here is a good article with a list of some great tips and tricks.

Best Practices

As a developer/designer, there are some of the best practices and guidelines that you can follow to make your app look good, or make it faster. Again, it depends upon you what to follow and what not.

Material design is a set of design guidelines created by Google which include everything from key lines, metrics, fonts, colors such that the user experience becomes attractive and intuitive. There’s a good YouTube Playlist for Android Development patterns where devs talk about common design and development patterns.

Libraries

Let’s say that you are trying to implement something for your app. Chances are, that a set of functionalities that you are thinking of developing yourself has already been developed by someone else and is kind enough to share their code for free. This is the true power of open source. Here is a good list of open source libraries for android developers.

Community

There are a lot of good and experienced android developers on online communities. They can help you out if you are stuck or need help with anything. Reddit is always a great place to start.

Indraneel Potnis
MENTOR
I'm a software programmer who has worked with a variety of technologies like Wordpress, J2EE, Android, Game development. I've published a book on game development with packt publications and a card game on Google Play store! My hobbies are trekking, reading and stargazing (and.. a TV series addict).