Book Image

Learning Kotlin by building Android Applications

By : Eunice Adutwumwaa Obugyei, Natarajan Raman
Book Image

Learning Kotlin by building Android Applications

By: Eunice Adutwumwaa Obugyei, Natarajan Raman

Overview of this book

<p>Today Kotlin is an official programming language for Android development and is widely adopted. Kotlin is expressive, concise, and powerful. It also ensures seamless interoperability with existing Android languages like JAVA and C++, which means that it's even easier for developers to use.</p> <p>This book adopts a project-style approach, where we focus on teaching Android development by building three different Android Application: a Tic-Tac-Toe application, a location- based alarm and a To-Do list application.</p> <p>The book begins by giving you a strong grasp of the Kotlin language and its APIs as a preliminary to building stunning applications for Android. You'll learn to set up an environment and as you progress through the chapters and the building of the different applications, the difficulty level will steadily grow.</p> <p>The book also introduces you to the Android Studio IDE, which plays an integral role in Android Development. It covers Kotlin's basic programming concepts such as functions, lambdas, properties, object-oriented code, safety aspects and type parameterization, testing, and concurrency, and helps you write Kotlin code to production.</p> <p>Finally, you'll be taken through the process of releasing your app on the Google Play Store. You will also be introduced to other app distribution channels such as Amazon App Store.</p> <p>As a bonus chapter, you will also learn how to use the Google Faces API to detect faces and add fun functionalities.</p>
Table of Contents (21 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Preface

"The purpose of education is to make good human beings with skills and expertise. Real education enhances the dignity of a human being and increases his or her self-respect. If only the real sense of education could be realized by each individual and carried forward in every field of human activity, the world will be so much a better place to live in."

— Dr. APJ Abdul Kalam

Over 2 billion Android users are active daily, and this reach of data to billions across the globe provides a real opportunity to make a difference. A phone, which was just a device for voice communication until recently, is notjust a phone anymore. Enabling and empowering the next billion users of Android devices will play a significant role in the future. 

The purpose of technology is to enable humanity, and the availability of powerful devices provides the opportunity for innovations and can improve the lives of people through technology. Whether it is an app that is built for farmers that provides useful information about the weather or prices of crops, or an app that is built for children with special needs to express themselves, or an app that is built for economically challenged women to run a small home-based business, the opportunities ahead are plenty and very exciting. 

This book aims to enable developers who would like to explore the power of Android and experience and enjoy the journey of building Android applications. The chapters have been organized to enable fresh developers to understand and start from the basics, or if you are an experienced developer, to get ahead and explore the power of Kotlin.

To make things much more interesting and easy on this app development journey, Google has added Kotlin as one of the official languages for Android application development. Kotlin is expressive, concise, and powerful. It also ensures seamless interoperability with existing Android languages such as Java and the runtime.

Who this book is for

This book will be useful for anyone who is starting fresh on Android application development. Learning Android app development has never been this exciting, as we have more than one choice language being officially supported by Google.  This book covers all the details required for Android app development using Kotlin, one step at a time, and enables readers to experience the journey as they make progress.

This book will also certainly help those who are already into Android application development using Java and trying to switch over to Kotlin or evaluate the ease of use of Kotlin. Android app developers who are well versed with Java will find the comparisons of code between Java and Kotlin very useful, and will be able to appreciate the power of Kotlin.

What this book covers

The objective of the book has been to ensure that both advanced Android app developers using Java and those starting to learn Android app development enjoy reading the book. 

Chapter 1Setting Up for Android Development, provides step-by-step information on setting up a system for Android app development, listing all details required to get started.

Chapter 2, Configuring Your Environment for Kotlin, details the steps required to configure the environment for Kotlin. Even though the latest and stable version of Android Studio provides Kotlin support out of the box, the information in this chapter will help you configure the development IDE of your choice.

Chapter 3Data Types, Variables, and Constants, introduces and discusses the details of Kotlin language constructs, such as data types, variables, and constants.

Chapter 4Classes and Objects, enhances the discussion on language constructs further by providing information on classes and objects and explains how to define and handle them.

Chapter 5Type Checks and Null Safety, discusses the salient features of Kotlin – type checks and Null Safety. Kotlin eliminates null reference completely by its design. 

Chapter 6, Functions and Lambdas, provides information on defining a function and using it in our program. This chapter also discusses Lambdas and provides information on their use.

Chapter 7, Developing Your Location-Based Alarm, discusses the fundamentals of Google's location-based services, using the Google Map API, and customizing a marker on map.

Chapter 8, Working with Google's Location Services, shows how to build apps using location-based services and explains how to build our own location-based alarm.

Chapter 9, Connecting the Outside World – Networking, covers the concepts of networking and communication with the outside world. We discuss the out-of-the-box options Android framework provides, as well third-party libraries such as Picasso and Glide. 

Chapter 10Developing a Simple To-Do List App, discusses building a user interface using Android Studio and provides information on working with ListViews and Dialogs.

Chapter 11Persisting with Databases, provides a brief introduction on relational databases, discusses CRUD operations on SQLite in detail, and looks at the use of ORMs, specifically the Room ORM from Google. 

Chapter 12Setting Reminders for Tasks, discusses setting up and pushing notifications to users from our app. It also explains how to utilize cloud services such as Firebase and Amazon SNS. We also discuss services and broadcast receivers. 

Chapter 13, Testing and Continuous Integration, discusses the importance of testing, the out-of-the-box support provided by Android Studio through Android Testing Support Library, how to use Crashlytics to track crash reports, and beta testing. This chapter also provides an introduction to CI and provides detailed steps on the use of tools such as Jenkins, Bamboo, and Fastlane.

Chapter 14, Making Your App Available to the World, explains how to publish your app to Google Play Store and Amazon App Store.

Chapter 15, Building an App Using the Google Faces API, discusses the use of the Google Faces API and how to build applications using it. This chapter also provides information on creating Paint instances and using a canvas to draw images. This chapter also discusses drawing shapes such as rectangles on the image.

To get the most out of this book

Having knowledge of object-oriented programming and the Android activity lifecycle will be useful, but is not mandatory. 

The latest stable version of Android Studio (version 3.1.3 at the time of publishing) provides support for Kotlin out of the box.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-Kotlin-by-building-Android-Applications. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

<dimen name="board_padding">16dp</dimen>
<dimen name="cell_margin">2dp</dimen>
<dimen name="large_text">64sp</dimen>

Any command-line input or output is written as follows:

brew cask install fastlane

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.