
eBook - ePub
Android application development with Kotlin
Build Your First Android App in No Time
- English
- ePUB (mobile friendly)
- Available on iOS & Android
eBook - ePub
About this book
Unleash the Power of Kotlin for Android App Development Key Features
- The book has theories explained elaborately along with Kotlin code and corresponding output to support the theoretical explanations. The Kotlin codes are provided with step-by-step comments to explain each instruction of the code
- The book is quite well balanced with programs and illustrative real-case problems
- The book is not just explaining theoretical concepts of the language. Still, it explains how the full-fledged application can be developed using some latest tools and technologies and create an excellent Android application using Kotlin
- Few of the chapter offers the quiz at the end of it. And you can revise the concepts quickly
- A rich sample application is created to demonstrate Kotlin's capability in various parts of the application
- Quite the latest concepts are discussed in depth. For example, Flow, NavigationComponent, Coroutine, ViewModel, and LiveData.
-
Description
This book aims to provide the knowledge around the fundamental concept of Kotlin languages, and it's an application in Android application development. It covers basic to advanced concepts with practical examples. Each chapter in this book is a step by step journey towards learning Kotlin and excel in various topics and concepts. It covers topics like data types, various functions, including lambdas and higher-order functions. It also covers advanced topics like Generics, Collections, DSL, Coroutine, etc. Most importantly, such concepts are explained with practical usage of it in Android application. You will get to know what is the best possible way to use these concepts while you develop an Android application. In this book, along with Kotlin, an attempt has been made where few Android-specific topics are also explained. For example, the application is using Architecture components, including ViewModel, LiveData, NavigationComponent, and also it uses Flow, which is a hot topic in Kotlin. While we learn this concept, along with that, we also develop a sample application where we can apply our learning and, in the end, have some tangible and measurable output.
Readers with little previous knowledge of Android application development can easily follow this book. Most of the chapters are code-heavy and focuses on practical usage of Kotlin's features. Each chapter has code on the GitHub. You can check out this code and try it out. Or you can develop in parallel and cherry-pick things from the sample code base as and when you need it. Few chapters also follow the quiz at the end, and you can self assess yourself by going through that quiz. In total there are ten chapters. What will you learn
- Know the basics and many advanced concepts of Android.
- Able to code in Kotlin for your Android application.
- You will know how architecture components can be used in Android application with Kotlin.
- Writing tests that use coroutine, Flow, LiveData, and ViewModel.
- What measures you need to take before you put an application in production.
- How agile practices can be applied before and after the application development is started. Who this book is for
The book is for readers with basic programming and android application development skills. The book is for any engineering graduates that wish to use Kotlin as a programming language for their Android application or wish to build a career in this direction. This book can also be useful for those who want to learn how testing aspects work for Android applications. The use cases and programs discussed in the book are self-explanatory and detailed with practical examples wherever necessary.
Frequently asked questions
Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weāve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere ā even offline. Perfect for commutes or when youāre on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Android application development with Kotlin by Hardik Trivedi in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Languages. We have over one million books available in our catalogue for you to explore.
Information
CHAPTER 1
Getting Started with Kotin for Android
āAny fool can write code that a computer can understand. Good programmers write code that humans can understand.ā
ā Martin Fowler
Many of us very much believe in the above quote. And might be wondering if the above statement is true why there is no programming language following this quote. With Kotlin your quest will come to an end. Welcome to the world of Kotlin.
Those who are still new to Kotlin, for them I would describe Kotlin as,
- A modern language to meet the modern age requirements.
- Very expressive and no verbosity.
- A statically typed language with a top-notch type of safety. For example, Null safety.
- And 100% interoperable with Java.
Kotlin as a language has a plethora of features to offer an abundance of applications. You can completely rely on this language and develop your application in Android, JavaFX, Spring boot, JavaScript, Node.js even iOS and embedded systems.
Structure
- Setting up an environment for Android app development
- Configure Kotlin and make it run with Android Studio and Gradle
- āHello Kotlinā program in Android written in Kotlin
- Brush up on Android basics
Writing Android applications in Kotlin is pure bliss. And with this, some of the coolest start-ups to Fortune 500 companies will agree. Image Credit - https://developer.android.com/kotlin (Data as on 1st July 2019):

Figure 1.1
Kotlin is owned by the IDE (Integrated Development Environment) giant JetBrains s.r.o. They are the best in class as far as IDEs are concerns. And with the above companies using it, you can see that Kotlin is in the safe hands of great open source developersā community. And it surely has a bright future. Kotlin is free and open-source under the Apache 2.0 license. JetBrains unveiled this project Kotlin back in 2011 and after that hardworking team was working on it to make it robust and rich with features. In February 2016 finally, the team released Kotlin v1.0. This was the first official stable release.
According to PYPL (PopularitY of Programming Language) index, Kotlin has made it to the top 15 in countries like India, United Kingdom, France, and Germany. And in the United States, it has secured rank 16. (The data has compiled against June 2019 as per http://pypl.github.io/PYPL.html)
During the annual developer conference, I/O-17 Google has announced its official support to Kotlin. From that day Kotlin has become the official language for Android application development. Google has also promised that for all documentations, tutorials, blogs, and code references on the developer website they are going to prefer Kotlin first. From the day of the announcement and to current day Kotlin has gained so much popularity in the Android developer community. In this chapter, you will soon realize the potential of this language and see how easy it is to start using it with its fantastic tooling support with Android Studio.
How does the Kotlin code look like?
In following Figure 1.2, some of the coolest features of Kotlin are highlighted.

Figure 1.2
You can see how lambdas are making the callbacks looks natural. Basically whatever you are seeing inside those curly braces is nothing but a function. A function passed as the last parameter can take the form of such curly braces and make the code look natural as if it is executed as a body of launch function.
Another feature that is emphasized here is named arguments, where you can bind a parameter along with its name at the time of calling it. With named arguments, you can take the liberty of changing order as well. This feature makes a lot of sense when there is a function with a lot of parameters. You can easily understand the parameters and their purpose just by looking at the function call.
For hardcore Java developer, a de novo feature is string interpolation. Itās a simple feature but incredibly useful when readability comes to a picture. You can easily concatenate strings by using $ sign in double-quotes.
Last but not least no semicolons (:).
How does Kotlin build process work with Android?
If you are a seasoned Android developer who knows about how Android build system works will surely have a question - Do I need to learn anything else as well to make Kotlin work with Android and build an APK file?
Answer The answer is NO. Just by knowing Koltin is enough. All your knowledge about the build system still stands true. Kotlin is a JVM language, this means if your existing code is working with JVM the Kotlin code will work as well with no changes in your build process. Kotlinās output is also the bytecode, in short, a .
class file. Any JVM can interpret the .class file and can process that and derive the instructions written inside it.JetBrains IDE will come with Kotlinās compiler by default. An IDE will compile your Kotlin code and produce the bytecode. For Android, the Android Studio has first-class support for Kotlin from version 3.0 onwards. Both Dalvik (A just in time compiler) and ART (An ahead of time compiler) can perceive bytecode. So for the Android build system, it doesnāt matter that the code is written on Kotlin or Java. Android doesnāt even know that code is written in which of these languages.
Refer to below Figure 1.3 to get more clarity around how Kotlin code can be used by Android and have no side effects at all:

Figure 1.3
Configure Kotlin in Android Studio
It was a dream come true for the Android developer community when Google announced the Android Studio as the official IDE for Android application development. It has evolved so beautifully that any feature you can think of or ask is there already. The Android Studio is amazingly customized for the need of the developer community. This makes application development fast and easy.
When Kotlin was announced as the official language for Android app development, there was no out of the box support for Kotlin. Developers have to perform a few steps to configure Kotlin into their Android project.
Note: If your Android Studio version is 3.0 or above skip this section. But if your Android Studio version is below 3.0 and does not want to upgrade to version 3.0 or above, you need to follow the below steps.
Note: If your Android Studio version is 3.0 or above skip this section. But if your Android Studio version is below 3.0 and do not want to upgrade to version 3.0 or above, you need to follow below steps. Installing Android Studio
Throughout the learning and application development, we will only and only use Android Studio. If you are not having Android Studio on your computer please below steps will help you to get it installed.
Downloading and installing Java
Android still relies heavily on Java Development Kit (JDK). Nowadays Android Studio comes with the latest OpenJDK embedded into the installer only to provide a jump start to entry-level developers. But it is always nice to have the latest version of JDK installed. Java has done a few releases in the last 2-3 years. While writing this book the latest release was Java 12. But for Android, itās recommended to have JDK 8 on your computer. Please download the JDK 8 from link https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Follow these instructions to install Java on your Microsoftās Windows or Appleās Mac computers, or Linux machines. https://java.com/en/download/help/download_options.xml
Downloading and installing Android Studio
Get the latest stable version o...
Table of contents
- Cover Page
- Title Page
- Copyright Page
- Dedication
- About the Author
- Acknowledgement
- Preface
- Errata
- Table of Contents
- 1. Getting Started with Kotin for Android
- 2. Kotlin Fundamentals
- 3. Go to the Depth of Kotlin
- 4. Design Patterns in Kotlin
- 5. Analyzing and Architecting a Meal Recipe App
- 6. Making Network Calls Using Coroutines
- 7. Kotlin-ize Remaining of Your App
- 8. Testing the Kotlin Code
- 9. Make Your App Production Ready
- 10. Kotlin Everywhere