Kotlin for Android Developers
Kotlin for Android Developers
Learn Kotlin the easy way while developing an Android App
About the Book
Google has officially announced Kotlin as a supported language to write Android Apps.
These are amazing news for Android developers, which now have the ability to use a modern and powerful language to make their job easier and funnier.
But this comes with other responsibilities. If you want to be a good candidate for new Android opportunities, Kotlin is becoming a new need most companies will ask for. So it's your time to start learning about it!
And "Kotlin for Android Developers" is the best tool. Recommended by both Google and Jetbrains, this book will guide through the process of learning all the new features that Java was missing, in an easy and fun way.
You'll be creating an Android app from ground using Kotlin as the main language. The idea is to learn the language by example, instead of following a typical structure. I'll be stopping to explain the most interesting concepts and ideas about Kotlin, comparing it with Java 7. This way, you can see what the differences are and which parts of the language will help you speed up your work.
This book is not meant to be a language reference, but a tool for Android developers to learn Kotlin and be able to continue with their own projects by themselves. I'll be solving many of the typical problems we have to face in our daily lives by making use of the language expressiveness and some other really interesting tools and libraries.
The book is very practical, so it is recommended to follow the examples and the code in front of a computer and try everything it's suggested. You could, however, take a first read to get a broad idea and then dive into practice.
As you could read in previous pages (and probably the site were you downloaded), this is a lean publication. This means that the book is written and progresses with you. I'll continually write new content and review the existing based on your comments and your suggestions. In the end, it will also be your book. I want this book to be the perfect tool for Android developers, and as such, all the help and ideas will be welcomed.
Thanks for becoming part of this exciting project.
Learn more Kotlin at: antonioleiva.com/kotlin
Reader Testimonials

Medet
This book is read in one breath. If you know the basic concept of android development and looking for the right source to enter the world of Kotlin for Android then this book is right for you. By going throughout the book, I was able to peek up basic concept of Kotlin and good coding practices. In the end, of my journey, I had been convinced that Kotlin is best for Android development.
Table of Contents
-
I. About this book
- What is “Kotlin for Android Developers” about
- II. Is this book for you?
- III. About the author
-
1 Introduction
- 1.1 What is Kotlin?
- 1.2 What do we get with Kotlin?
-
2 Getting ready
- 2.1 Android Studio
- 2.2 Install Kotlin plugin
-
3 Creating a new project
- 3.1 Create a new project in Android Studio
- 3.2 Convert MainActivity to Kotlin code
- 3.3 Configure Kotlin in project
- 3.4 Include some other useful configuration
- 3.5 Test that everything works
-
4 Classes and functions
- 4.1 How to declare a class
- 4.2 Class inheritance
- 4.3 Functions
- 4.4 Constructor and functions parameters
-
5 Writing your first class
- 5.1 Creating the layout
- 5.2 The Recycler Adapter
-
6 Variables and properties
- 6.1 Basic types
- 6.2 Variables
- 6.3 Properties
-
7 Anko and Extension Functions
- 7.1 What is Anko?
- 7.2 Start using Anko
- 7.3 Extension functions
-
8 Retrieving data from API
- 8.1 Performing a request
- 8.2 Performing the request out of the main thread
-
9 Data Classes
- 9.1 Extra functions
- 9.2 Copying a data class
- 9.3 Mapping an object into variables
-
10 Parsing data
- 10.1 Converting JSON to data classes
- 10.2 Shaping the domain layer
- 10.3 Drawing the data in the UI
-
11 Operator overloading
- 11.1 Operators tables
- 11.2 An example
- 11.3 Operators in extension functions
- 12 Making the forecast list clickable
-
13 Lambdas
- 13.1 Simplifying setOnClickListener()
- 13.2 Click listener for ForecastListAdapter
- 13.3 Extending the language
-
14 Visibility Modifiers
- 14.1 Modifiers
- 14.2 Constructors
- 14.3 Reviewing our code
-
15 Kotlin Android Extensions
- 15.1 How to use Kotlin Android Extensions
- 15.2 Kotlin Android Extensions in 1.1.4
- 15.3 Refactoring our code
-
16 Application Singleton and Delegated Properties
- 16.1 Application Singleton
- 16.2 Delegated Properties
- 16.3 Standard Delegates
- 16.4 How to create a custom delegate
- 16.5 Reimplementing the App Singleton
-
17 Creating an SQLiteOpenHelper
- 17.1 ManagedSqliteOpenHelper
- 17.2 Tables definition
- 17.3 Implementing SqliteOpenHelper
- 17.4 Dependency injection
-
18 Collections and functional operations
- 18.1 Aggregate operations
- 18.2 Filtering operations
- 18.3 Mapping operations
- 18.4 Elements operations
- 18.5 Generation operations
- 18.6 Ordering operations
-
19 Saving and requesting data from the database
- 19.1 Creating database model classes
- 19.2 Writing and requesting data
-
20 Null safety in Kotlin
- 20.1 How Null types work
- 20.2 Nullity and Java libraries
- 21 Creating the business logic to data access
-
22. Flow control and ranges
- 22.1 If Expression
- 22.2 When expression
- 22.3 For loops
- 22.4 While and do/while loops
- 22.5 Ranges
-
23 Creating a Detail Activity
- 23.1 Preparing the request
- 23.2 Providing a new activity
- 23.3 Start an activity: reified functions
-
24 Interfaces and Delegation
- 24.1 Interfaces
- 24.2 Delegation
- 24.3 Implementing an example in our App
-
25 Generics
- 25.1 Basics
- 25.2 Variance
- 25.3 Generics examples
-
26 Settings Screen
- 26.1 Creating the settings activity
- 26.2 Accessing Shared Preferences
- 26.3 Generic preference delegate
-
27 Coroutines since Kotlin 1.3
- 27.1 Coroutines goal: The problem
- 27.2 What are coroutines?
- 27.3 Using coroutines in our example
-
28 Testing your App
- 28.1 Unit testing
- 28.2 Mocking closed classes
- 28.3 Instrumentation tests
-
29 Extra concepts
- 29.1 Nested classes
- 29.2 Enum classes
- 29.3 Sealed classes
- 29.4 Exceptions
-
30 Java interoperability
- 30.1 Package-level functions
- 30.2 Extension functions
- 30.3 Function overloads
- 30.4 Instance and static fields
- 30.5 Data classes
- 30.6 Sealed classes
- 30.7 Inline functions and reified types
- 31 Conclusion
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned$12,307,240writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Personal Finance
Jason AndersonThis textbook provides an in-depth analysis on personal finance that is both practical and straightforward in its approach. It has been written in such a way that the readers can gain knowledge without getting overwhelmed by the technical terms. Suitable for both beginners and advanced learners.
Getting to Know IntelliJ IDEA
Trisha Gee and Helen ScottIf we treat our IDE as a text editor, we are doing ourselves a disservice. Using a combination of tutorials and a questions-and-answers approach, Getting to Know IntelliJ IDEA will help you find ways to use IntelliJ IDEA that enable you to work comfortably and productively as a professional developer.
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
Machine Learning Q and AI
Sebastian Raschka, PhDHave you recently completed a machine learning or deep learning course and wondered what to learn next? With 30 questions and answers on key concepts in machine learning and AI, this book provides bite-sized bits of knowledge for your journey to becoming a machine learning expert.
Stats One
William FooteThe Rails 7 Way
Obie Fernandez, Lucas Dohmen, and Tom Henrik AadlandThe Rails™ 7 Way is the comprehensive, authoritative reference guide for professionals delivering production-quality code using modern Ruby on Rails. It illuminates the entire Rails 7 API, its most powerful idioms, design approaches, and libraries. Building on the previous editions, this edition has been heavily refactored and updated.
Gradual Modularization for Ruby and Rails
Stephan HagemannGet yourself a new tool to manage your Rails application and your growing engineering organization! Prevent the ball-of-mud (and fix it!). Go for microservices or SOA if it makes sense not just because you don't have any other tool. Do all this through a low-overhead tool: packages. Enable better conversations to make practical changes today.
Top Bundles
- #1
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
1500 QUIZ COMMENTATI (3 libri)
3 Books
Tre libri dei QUIZ MMG Commentati al prezzo di DUE! I QUIZ dei concorsi ufficiali di Medicina Generale relativi agli anni: 2000-2001-2003-2012-2013-2014-2015-2016-2017-2018-2019-2020-2021 +100 inediti Raccolti in unico bundle per aiutarvi nello studio e nella preparazione al concorso. All'interno di ogni libro i quiz sono stati suddivisi per... - #4
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #5
Practical FP in Scala + Functional event-driven architecture
2 Books
Practical FP in Scala (A hands-on approach) & Functional event-driven architecture, aka FEDA, (Powered by Scala 3), together as a bundle! The content of PFP in Scala is a requirement to understand FEDA so why not take advantage of this bundle!? - #6
Modern C++ Collection
3 Books
Get All about Modern C++C++ Standard Library, including C++20Concurrency with Modern C++, including C++20C++20Each book has about 200 complete code examples. Updates are included. When I update one of the books, you immediately get the updated bundle. You can expect significant updates to each new C++ standard (C++23, C++26, .. ) and also... - #7
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #9
Development and Deployment of Multiplayer Online Games, Part ARCH. Architecture (Vol. I-III)
3 Books
What's the Big Idea? The idea behind this book is to summarize the body of knowledge that already exists on multiplayer games but is not available in one single place.And quite a fewof the issues discussed within this series (planned as three nine volumes ~300 pages each), while known in the industry, have not been published at all (except for... - #10
Growing Agile: The Complete Coach's Guide
7 Books
Growing Agile: Coach's Guide Series This bundle provides a collection of training and workshop plans for a variety of agile topics. The series is aimed at agile coaches, trainers and ScrumMasters who often find themselves needing to help teams understand agile concepts. Each book in the series provides the plans, slides, handouts and activity...