How to Build Android Apps with Kotlin

Book description

Master the fundamentals of Android programming and apply your skills to create scalable and reliable apps using industry best practices

Key Features

  • Build apps with Kotlin, Google’s preferred programming language for Android development
  • Unlock solutions to development challenges with guidance from experienced Android professionals
  • Improve your apps by adding valuable features that make use of advanced functionality

Book Description

Are you keen to get started building Android 11 apps, but don’t know where to start? How to Build Android Apps with Kotlin is a comprehensive guide that will help kick-start your Android development practice.

This book starts with the fundamentals of app development, enabling you to utilize Android Studio and Kotlin to get started building Android projects. You'll learn how to create apps and run them on virtual devices through guided exercises. Progressing through the chapters, you'll delve into Android’s RecyclerView to make the most of lists, images, and maps, and see how to fetch data from a web service.

Moving ahead, you'll get to grips with testing, learn how to keep your architecture clean, understand how to persist data, and gain basic knowledge of the dependency injection pattern. Finally, you'll see how to publish your apps on the Google Play store.

You'll work on realistic projects that are split up into bitesize exercises and activities, allowing you to challenge yourself in an enjoyable and attainable way. You'll build apps to create quizzes, read news articles, check weather reports, store recipes, retrieve movie information, and remind you where you parked your car.

By the end of this book, you'll have the skills and confidence to build your own creative Android applications using Kotlin.

What you will learn

  • Create maintainable and scalable apps using Kotlin
  • Understand the Android development lifecycle
  • Simplify app development with Google architecture components
  • Use standard libraries for dependency injection and data parsing
  • Apply the repository pattern to retrieve data from outside sources
  • Publish your app on the Google Play store

Who this book is for

If you want to build your own Android applications using Kotlin but are unsure of how to begin, then this book is for you. To easily grasp the concepts in this book, it is recommended that you already have a basic understanding of Kotlin, or experience in a similar programming language and a willingness to brush up on Kotlin before you start.

Table of contents

  1. How to Build Android Apps with Kotlin
  2. Preface
    1. About the Book
      1. ABOUT THE AUTHORS
      2. Audience
      3. About the Chapters
      4. Conventions
      5. Before You Begin
      6. Minimum Hardware Requirements
      7. Software Requirements
      8. Installation and Setup
      9. Installing the Code Bundle
      10. Get in touch
      11. Please leave a review
  3. 1. Creating Your First App
    1. Introduction
    2. Creating an Android Project with Android Studio
      1. Exercise 1.01: Creating an Android Studio Project for Your App
    3. Setting Up a Virtual Device and Running Your App
      1. Exercise 1.02: Setting Up a Virtual Device and Running Your App on It
    4. The Android Manifest
      1. Exercise 1.03: Configuring the Android Manifest Internet Permission
    5. Using Gradle to Build, Configure, and Manage App Dependencies
      1. Project-Level build.gradle file
      2. App-Level build.gradle
      3. Exercise 1.04: Exploring how Material Design is used to theme an app
    6. Android Application Structure
      1. Exercise 1.05: Adding Interactive UI Elements to Display a Bespoke Greeting to the User
      2. Accessing Views in layout files
      3. Further Input Validation
      4. Activity 1.01: Producing an App to Create RGB Colors
    7. Summary
  4. 2. Building User Screen Flows
    1. Introduction
    2. The Activity Lifecycle
      1. Exercise 2.01: Logging the Activity Callbacks
    3. Saving and Restoring the Activity State
      1. Exercise 2.02: Saving and Restoring the State in Layouts
      2. Exercise 2.03: Saving and Restoring the State with Callbacks
    4. Activity Interaction with Intents
      1. Exercise 2.04: An Introduction to Intents
      2. Exercise 2.05: Retrieving a Result from an Activity
    5. Intents, Tasks, and Launch Modes
      1. Exercise 2.06: Setting the Launch Mode of an Activity
      2. Activity 2.01: Creating a Login Form
    6. Summary
  5. 3. Developing the UI with Fragments
    1. Introduction
    2. The Fragment Lifecycle
      1. onAttach
      2. onCreate
      3. onCreateView
      4. onViewCreated
      5. onActivityCreated
      6. onStart
      7. onResume
      8. onPause
      9. onStop
      10. onDestroyView
      11. onDestroy
      12. onDetach
      13. Exercise 3.01: Adding a Basic Fragment and the Fragment Lifecycle
      14. Exercise 3.02: Adding Fragments Statically to an Activity
    3. Static Fragments and Dual-Pane Layouts
      1. Exercise 3.03: Dual-Pane Layouts with Static Fragments
    4. Dynamic Fragments
      1. Exercise 3.04: Adding Fragments Dynamically to an Activity
    5. Jetpack Navigation
      1. Exercise 3.05: Adding a Jetpack Navigation Graph
      2. Activity 3.01: Creating a Quiz on the Planets
    6. Summary
  6. 4. Building App Navigation
    1. Introduction
    2. Navigation Overview
    3. Navigation Drawer
      1. Exercise 4.01: Creating an App with a Navigation Drawer
    4. Bottom Navigation
      1. Exercise 4.02: Adding Bottom Navigation to Your App
    5. Tabbed Navigation
      1. Exercise 4.03: Using Tabs for App Navigation
      2. Activity 4.01: Building Primary and Secondary App Navigation
    6. Summary
  7. 5. Essential Libraries: Retrofit, Moshi, and Glide
    1. Introduction
    2. Fetching Data from a Network Endpoint
      1. Exercise 5.01: Reading Data from an API
    3. Parsing a JSON Response
      1. Exercise 5.02: Extracting the Image URL from the API Response
    4. Loading Images from a Remote URL
      1. Exercise 5.03: Loading the Image from the Obtained URL
      2. Activity 5.01: Displaying the Current Weather
    5. Summary
  8. 6. RecyclerView
    1. Introduction
    2. Adding RecyclerView to Our Layout
      1. Exercise 6.01: Adding an Empty RecyclerView to Your Main Activity
    3. Populating the RecyclerView
      1. Exercise 6.02: Populating Your RecyclerView
    4. Responding to Clicks in RecyclerView
      1. Exercise 6.03: Responding to Clicks
    5. Supporting Different Item Types
      1. Exercise 6.04: Adding Titles to RecyclerView
    6. Swiping to Remove Items
      1. Exercise 6.05: Adding Swipe to Delete Functionality
    7. Adding Items Interactively
      1. Exercise 6.06: Implementing an "Add A Cat" Button
      2. Activity 6.01: Managing a List of Items
    8. Summary
  9. 7. Android Permissions and Google Maps
    1. Introduction
    2. Requesting Permissions from the User
      1. Exercise 7.01: Requesting the Location Permission
    3. Showing a Map of the User's Location
      1. Exercise 7.02: Obtaining the User's Current Location
    4. Map Clicks and Custom Markers
      1. Exercise 7.03: Adding a Custom Marker Where the Map Was Clicked
      2. Activity 7.01: Creating an App to Find the Location of a Parked Car
    5. Summary
  10. 8. Services, WorkManager, and Notifications
    1. Introduction
    2. Starting a Background Task Using WorkManager
      1. Exercise 8.01: Executing Background Work with the WorkManager Class
    3. Background Operations Noticeable to the User – Using a Foreground Service
      1. Exercise 8.02: Tracking Your SCA's Work with a Foreground Service
      2. Activity 8.01: Reminder to Drink Water
    4. Summary
  11. 9. Unit Tests and Integration Tests with JUnit, Mockito, and Espresso
    1. Introduction
    2. JUnit
    3. Android Studio Testing Tips
    4. Mockito
      1. mockito-kotlin
      2. Exercise 9.01: Testing the Sum of Numbers
    5. Integration Tests
      1. Robolectric
      2. Espresso
      3. Exercise 9.02: Double Integration
    6. UI Tests
      1. Exercise 9.03: Random Waiting Times
    7. Test-Driven Development
      1. Exercise 9.04: Using TDD to Calculate the Sum of Numbers
      2. Activity 9.01: Developing with TDD
    8. Summary
  12. 10. Android Architecture Components
    1. Introduction
    2. ViewModel and LiveData
      1. ViewModel
      2. LiveData
      3. Exercise 10.01: Creating a Layout with Configuration Changes
      4. Exercise 10.02: Adding a ViewModel
      5. Exercise 10.03: Sharing our ViewModel between the Fragments
      6. Exercise 10.04: Adding LiveData
    3. Room
      1. Entities
      2. DAO
      3. Setting Up the Database
      4. Third-Party Frameworks
      5. Exercise 10.05: Making a Little Room
    4. Customizing Life Cycles
      1. Exercise 10.06: Reinventing the Wheel
      2. Activity 10.01: Shopping Notes App
    5. Summary
  13. 11. Persisting Data
    1. Introduction
    2. Repository
      1. Exercise 11.01: Creating a Repository
      2. Exercise 11.02: Adding Error Handling
    3. Preferences
      1. SharedPreferences
      2. Exercise 11.03: Wrapping SharedPreferences
      3. PreferenceFragment
      4. Exercise 11.04: Customized Settings
    4. Files
      1. Internal Storage
      2. External Storage
      3. FileProvider
      4. Storage Access Framework (SAF)
      5. Asset Files
      6. Exercise 11.05: Copying Files
    5. Scoped Storage
      1. Camera and Media Storage
      2. Exercise 11.06: Taking Photos
      3. Activity 11.01: Dog Downloader
    6. Summary
  14. 12. Dependency Injection with Dagger and Koin
    1. Introduction
    2. Manual DI
      1. Exercise 12.01: Manual Injection
    3. Dagger
      1. Consumers
      2. Providers
      3. Connectors
      4. Qualifiers
      5. Scopes
      6. Subcomponents
      7. Exercise 12.02: Dagger Injection
      8. Dagger Android
      9. Exercise 12.03: Changing Injectors
    4. Koin
      1. Exercise 12.04: Koin Injection
      2. Activity 12.01: Injected Repositories
      3. Activity 12.02: Koin-Injected Repositories
    5. Summary
  15. 13. RxJava and Coroutines
    1. Introduction
    2. RxJava
      1. Observables, Observers, and Operators
      2. Schedulers
      3. Adding RxJava to Your Project
      4. Using RxJava in an Android Project
      5. Exercise 13.01: Using RxJava in an Android Project
      6. Modifying Data with RxJava Operators
      7. Exercise 13.02: Using RxJava Operators
    3. Coroutines
      1. Creating Coroutines
      2. Adding Coroutines to Your Project
      3. Exercise 13.03: Using Coroutines in an Android App
    4. Transforming LiveData
      1. Exercise 13.04: LiveData Transformations
    5. Coroutines Channels and Flows
    6. RxJava versus Coroutines
      1. Activity 13.01: Creating a TV Guide App
    7. Summary
  16. 14. Architecture Patterns
    1. Introduction
    2. MVVM
    3. Data Binding
      1. Exercise 14.01: Using Data Binding in an Android Project
    4. Retrofit and Moshi
    5. The Repository Pattern
      1. Exercise 14.02: Using Repository with Room in an Android Project
    6. WorkManager
      1. Exercise 14.03: Adding WorkManager to an Android Project
      2. Activity 14.01: Revisiting the TV Guide App
    7. Summary
  17. 15. Animations and Transitions with CoordinatorLayout and MotionLayout
    1. Introduction
    2. Activity Transitions
      1. Adding Activity Transitions through XML
      2. Adding Activity Transitions through Code
      3. Starting an Activity with an Activity Transition
      4. Exercise 15.01: Creating Activity Transitions in an App
      5. Adding a Shared Element Transition
      6. Starting an Activity with the Shared Element Transition
      7. Exercise 15.02: Creating the Shared Element Transition
    3. Animations with CoordinatorLayout
    4. Animations with MotionLayout
      1. Adding MotionLayout
      2. Creating Animations with MotionLayout
      3. Exercise 15.03: Adding Animations with MotionLayout
      4. The Motion Editor
      5. Debugging MotionLayout
      6. Modifying the MotionLayout Path
      7. Exercise 15.04: Modifying the Animation Path with Keyframes
      8. Activity 15.01: Password Generator
    5. Summary
  18. 16. Launching Your App on Google Play
    1. Introduction
    2. Preparing Your Apps for Release
      1. Versioning Apps
      2. Creating a Keystore
      3. Exercise 16.01: Creating a Keystore in Android Studio
      4. Storing the Keystore and Passwords
      5. Signing Your Apps for Release
      6. Exercise 16.02: Creating a Signed APK
      7. Android App Bundle
      8. Exercise 16.03: Creating a Signed App Bundle
      9. App Signing by Google Play
    3. Creating a Developer Account
    4. Uploading an App to Google Play
      1. Creating a Store Listing
        1. App Details
        2. Graphic Assets
      2. Preparing the Release
        1. APK/App Bundle
      3. Rolling Out a Release
    5. Managing App Releases
      1. Release Tracks
        1. Feedback Channel and Opt-in Link
        2. Internal Testing
        3. Closed Testing
        4. Open Testing
      2. Staged Rollouts
      3. Managed Publishing
      4. Activity 16.01: Publishing an App
    6. Summary

Product information

  • Title: How to Build Android Apps with Kotlin
  • Author(s): Alex Forrester, Eran Boudjnah, Alexandru Dumbravan, Jomar Tigcal
  • Release date: February 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781838984113