Android application development with Kotlin: Build Your First Android App In No Time
- Length: 402 pages
- Edition: 1
- Language: English
- Publisher: BPB Publications
- Publication Date: 2020-05-12
- ISBN-10: 9389423503
- ISBN-13: 9789389423501
- Sales Rank: #6317684 (See Top 100 Books)
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.
Cover Page Title Page Copyright Page Dedication About the Author Acknowledgement Preface Errata Table of Contents 1. Getting Started with Kotin for Android Structure How does the Kotlin code look like? How does Kotlin build process work with Android? Configure Kotlin in Android Studio Downloading and installing Java Downloading and installing Android Studio Installing Kotlin plugin Updating build.gradle Add classpath into the project’s build.gradle Add Koltin as a library Create a new project Setting up Android emulator Display “Hello Kotlin” Understanding the basics of Android Activity Activity lifecycle Intent Implicit Intent Explicit Intent Building Intent AndroidManifest.xml Fragment Context Trying out Kotlin Wrapping up 2. Kotlin Fundamentals Structure Understanding basic types Numbers String Booleans Understanding variables Type inference Understanding the scope of the variable Naming a variable Functions in Kotlin Functions and parameters Functions and return type Named arguments Default arguments Why Java does not support default arguments? Functions as an expression Variable arguments Beyond arguments and return types Local function Extension function Infix function Top-level functions Playing with String Standard extension properties and functions String template String comparison Comparing value Comparing reference Using .equals() function Escaped string Controlling program flow Decision making If, else-if, else ‘when’ expression ‘when’ as switch case ‘when’ with objects Perform iteratively Using for loop The great while loop Jumping off the branches Handling errors and exceptions Checked exception Playing around functions Useful extension function Managing files Scoping functions Using ‘with’ and ‘run’ functions Using ‘apply’ and ‘also’ function Using ‘let’ function Returning multiple values from the function Pair<A, B> Triple<A, B, C> Destructuring declaration Being late or lazy lateinit lazy Type aliases Type casting Smart casting Safe casting Classes Creating a class Properties Types of constructors Implicit primary constructor Primary constructor Secondary constructor Private constructor Interfaces Defining an interface Implementing an interface Inheritance Visibility modifiers Data classes equals()/hashCode() toString() componentN() copy() Nested and inner classes Accessing outer class inside the nested and inner class Initialising nested and inner class Enum classes Sealed classes Defining sealed class Using sealed class Wrapping up Pop quiz Answers 3. Go to the Depth of Kotlin Structure Kotlin’s type of system Null safety Safe call operator Elvis operator (?:) Non-null assertion (!!) Any, Nothing, and Unit Any Nothing Unit Delegated properties lazy observable and vetoable vetoable Binding property from the map Writing custom delegated property Lambdas Lambdas and functional interfaces Higher-order functions Using lambdas as the callback Passing function as a parameter Passing function lambda style Higher order function as an extension function Returning a function Using callable reference Inline function What’s going on behind the scene of the inline function Collections in Kotlin List Functional initializers List and operator overloading Reversing a List Sorting Collections Sorting List Sorting a Map Sorting a Set Sequence vs Iterable When Sequences needs to be used Taking advantage of Generics Why Generics? Generic and type safety Generics and constraints Generics and variance Covariance Contravariance Use site variance or type projection DSL – Type-safe builders Learn how to create DSL Bijou yet significant Kotlin features Import alias Naming companion object Changing class name Wrapping up Pop quiz Answers 4. Design Patterns in Kotlin Structure Objective Builder pattern Singleton pattern Decorator pattern Facade pattern Observer pattern Chain of responsibility pattern Wrapping up 5. Analyzing and Architecting a Meal Recipe App Structure Understand the requirements for a meal recipe app User story mapping Developing user interface Creating layouts ConstraintLayout Creating layout using DSL Theming and styling Styles Themes Creating activities and fragments Architecture component Navigation components Preparing navigation graph Displaying fragments on MainActivity Creating data repository Reading input stream Converting raw data into application data Creating ViewModel with the help of generics What are generics? Refactor view model factory using generics Troubleshoot your dry run Extension function and generics Get rid of findViewById() Data classes Data level classes Presentation level classes Dependency injection Comparison between various DI frameworks Using Koin Setting up Koin Declaring modules Starting Koin Injecting your dependencies Wrapping up 6. Making Network Calls Using Coroutines Structure What is coroutine? Using coroutine Creating coroutine Understanding the scope Creating a Job Canceling a Job Managing asynchronous coroutine Suspending a function Measuring coroutine’s performance sumWithoutAsync sumWithAsync Beyond coroutine Job – A Flow Emit and collect a Flow Inside Flow Canceling a Flow Operators in Flow map operator filter operator Behaviour The behavior of Flow is sequential Optimize the Flow using the buffer Managing multiple flows The zip operator The combine operator Operator combine without extension function combine vs combineTransform Exception handling in Flow catch as an operator Declarative catch Connect application to the remote server Setting up dependency Refactoring repository layer Retrofit, Coroutine, and Flow Inside Repository Inside ViewModel Inside View Wrapping up 7. Kotlin-ize Remaining of Your App Structure Error handling approaches Handling exception inside the repository Refactor emitting the response Show error to the user Approach 1: Using a sealed class Approach 2: Using multiple observer and LiveData Write utility using extension function The simplest way to show and hide any view Formatting string using an extension function Checking internet connectivity using an extension function Extension function and InputStream Extension function and higher-order function Implicit intent and extension function Using KTX and Splitties Convert build.gradle from Groovy to Kotlin DSL Why one would ditch Groovy? Pros of using Kotlin DSL Cons of using Kotlin DSL Step 1: Updating the Gradle distribution version Step 2: Getting rid of all single quotes (‘) Step 3: Changing Groovy function calls Step 4: Updating settings.gradle Step 5: Updating project level build.gradle Step 6: Updating app-level build.gradle Wrapping up 8. Testing the Kotlin Code Structure Application testing approach Why I should care about tests? Quality of code Makes refactoring easy Find bugs during development Great cost saver Enforce good structural code Testing Pyramid Small tests Medium tests Large tests Writing unit tests using JUnit5 Features of JUnit5 Rich set of annotations DisplayName Grouped assertions Asserting exceptions Configure JUnit5 for Android app Unit test your repository layer Unit test suspend function Using inner classes to group your test cases Unit testing ViewModel and LiveData Best practices to follow while writing test cases Verify one scenario at a time Make your test readable Divide and rule Find a good balance between unit and integration test Fixed and shared test data Wrapping up 9. Make Your App Production Ready Structure Package restructuring Writing safe code in Kotlin Use val over var Use data class as POJO Return immutable type The static code analysis tool Advantages of static code analysis tool Early and frequent checks Increases robustness of your code Reports and modelling diagrams detekt vs ktlint Fine tune default config Enabling code commenting Exception handling Some small yet significant improvements Changes we did as per detekt recommendation Removing wildcard imports Adding missing documentation Parameter list wrapping Dokka as documentation engine Dokka report Analytics using Firebase Wrapping up 10. Kotlin Everywhere Structure Kotlin ecosystem Kotlin – Jack of all trades Kotlin for the standalone app Why TornadoFX Kotlin for server-side development Kotlin for JavaScript Kotlin for iOS using Kotlin multiplatform What part of the code will be shared across Android and iOS? What tools do we need? Create an Android application Creating a shared module Writing common implementation Writing Android implementation Writing iOS implementation Integrating shared code in Android Integrating shared code with iOS Generating iOS framework from SharedCode module Keeping SharedCode up to date Some useful learning resources Libraries Websites and blogs Wrapping up
Donate to keep this site alive
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.