O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Android Development with Kotlin

Book Description

Master Android development using a variety of Kotlin features

About This Book

  • Leverage specific features of Kotlin to ease Android application development
  • An illustrative guide that will help you write code based Kotlin language to build robust Android applications
  • Filled with various practical examples build amazing Android project using Kotlin so you can easily apply your knowledge to real world scenarios

Who This Book Is For

The book is for developers who want to build amazing Android applications in an easy and effective way. Basic knowledge of Kotlin is assumed, but you do not need any familiarity with Android development.

What You Will Learn

  • Understand the basics of Android development with Kotlin
  • Get to know the key concepts in Android development
  • See how to create modern mobile applications for the Android platform
  • Adjust your application's look and feel
  • Know how to persist and share application database
  • Work with Services and other concurrency mechanisms
  • Write effective tests
  • Migrate an existing Java-based project to Kotlin

In Detail

Kotlin is a programming language intended to be a better Java, and it's designed to be usable and readable across large teams with different levels of knowledge. As a language, it helps developers build amazing Android applications in an easy and effective way.

This book begins by giving you a strong grasp of Kotlin's features in the context of Android development and its APIs. Moving on, you'll take steps toward building stunning applications for Android. The book will show you how to set up the environment, and the difficulty level will grow steadily with the applications covered in the upcoming chapters.

Later on, the book will introduce you to the Android Studio IDE, which plays an integral role in Android development. We'll use Kotlin's basic programming concepts such as functions, lambdas, properties, object-oriented code, safety aspects, type parameterization, testing, and concurrency, which will guide you through writing Kotlin code into production. We'll also show you how to integrate Kotlin into any existing Android project.

Style and approach

In this book, you'll master Android development using Kotlin through real application examples. We'll introduce you to basic Android concepts and offer guidance from the first steps to the final project. In each chapter, we'll develop one important application functionality as a development milestone. As we progress, you'll become more experienced in Android and our application will progress toward a real-world product. Finally, when we complete the application's development, we'll write proper tests to ensure it's production ready.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Starting with Android
    1. Why Kotlin?
    2. Kotlin for Android - it's official
    3. Downloading and configuring Android Studio
    4. Setting up Android emulators
      1. Creating a new AVD instance
      2. Duplicating an existing AVD and modifying it by need
    5. Android Debug Bridge
    6. Other important tools
    7. Initializing a Git repository
    8. Creating an Android project
    9. Setting up Gradle
    10. Explaining directory structure
    11. Defining build types and flavors
    12. Additional libraries
    13. Getting familiar with Android Manifest
    14. Main Application class
    15. Your first screen
    16. Summary
  3. Building and Running
    1. Running your first Android application
    2. Meet the Logcat
      1. First case
    3. Using the Gradle build tool
    4. Debug your application
    5. Summary
  4. Screens
    1. Analyzing the mockup plan
      1. Defining application activities
    2. Android layouts
      1. Using EditText views
      2. The margins attribute
      3. The padding attribute
      4. Checking out the gravity attribute
      5. Looking at other attributes
    3. Understanding Android Context
    4. Understanding fragments
      1. Fragment manager
      2. Fragments stack
    5. Creating View Pager
    6. Making animations with transitions
    7. Dialog fragments
    8. Notifications
    9. Other important UI components
    10. Summary
  5. Connecting Screen Flow
    1. Creating an application bar
    2. Using the navigation drawer
    3. Connecting activities
    4. Looking deeper into Android Intents
    5. Passing information between activities and fragments
    6. Summary
  6. Look and Feel
    1. Themes in the Android Framework
    2. Styles in Android
      1. Working with assets
      2. Using custom fonts
    3. Applying coloring
    4. Make your buttons look pretty
    5. Setting animations
      1. Animation sets in Android
    6. Summary
  7. Permissions
    1. Permissions from Android Manifest
    2. Requesting permissions
    3. Doing it the Kotlin way
    4. Summary
  8. Working with Databases
    1. Introduction to SQLite
      1. Benefits
    2. Describing our database
    3. CRUD operations
      1. Insert CRUD operation
      2. Update CRUD operation
      3. Delete CRUD operation
      4. Select CRUD operation
      5. Tying things together
    4. Summary
  9. Android Preferences
    1. What are Android preferences?
    2. How can you use them?
      1. Editing (storing) preferences
      2. Removing preferences
    3. Defining your own preferences manager
    4. Summary
  10. Concurrency in Android
    1. Introduction to Android concurrency
      1. Main thread
    2. Handlers and threads
      1. AsyncTask
    3. Understanding Android Looper
      1. Preparing the Looper
      2. Delayed execution
    4. Summary
  11. Android Services
    1. Service categorization
      1. Foreground Android services
      2. Background Android services
      3. Bound Android services
    2. Android service basics
      1. Declaring your service
      2. Starting the service
      3. Stopping the service
      4. Binding to Android service
      5. Stopping the service
      6. Service lifecycle
    3. Defining the main application service
    4. Defining the intent service
    5. Summary
  12. Messaging
    1. Understanding Android broadcasts
      1. System broadcasts
      2. Listening for broadcasts
      3. Registering from the context
      4. Receivers execution
      5. Sending broadcasts
    2. Creating your own broadcast messages
    3. Using on boot and on shutdown broadcasts
    4. Listening for network events
    5. Summary
  13. Backend and API
    1. Identifying entities used
    2. Working with data classes
    3. Connect data models to a database
    4. Introduction to Retrofit
      1. Defining Retrofit service
      2. Building a Retrofit service instance
    5. Introduction to Gson with Kotson library
    6. What else is available?
      1. Retrofit alternative
      2. Gson alternative
    7. Executing our first API call
    8. Content providers
    9. Android adapters
    10. Content loaders
    11. Data binding
    12. Using lists
    13. Using grids
    14. Implementing drag and drop
    15. Summary
  14. Tuning Up for High Performance
    1. Optimizing layouts
    2. Optimizing battery life
    3. Keeping your application responsive
    4. Summary
  15. Testing
    1. Adding dependencies
    2. Updating folder structure
    3. Writing your first test
    4. Using test suites
      1. How to test UI
    5. Running tests
      1. Running unit tests
      2. Running instrumentation tests
    6. Summary
  16. Migration to Kotlin
    1. Preparing the migration
    2. Danger signs
    3. Updating dependencies
    4. Converting classes
    5. Refactoring and cleanup
    6. Summary
  17. Deploying Your Application
    1. Preparing for deployment
    2. Code obfuscation
    3. Signing your application
    4. Publishing to Google Play
    5. Summary