Unleash the power of Android programming to build 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
Looking to kick-start your app development journey with Android 13, but don't know where to start? How to Build Android Apps with Kotlin is a comprehensive guide that will help jump-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 with 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.
You'll also get to grips with testing, learning how to keep your architecture clean, understanding how to persist data, and gaining 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 app 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
• Build user interfaces using Jetpack Compose
• Explore Android asynchronous programming with Coroutines and the Flow API
• Publish your app on the Google Play store
Who this book is for
If you want to build Android applications using Kotlin but are unsure of how and where to begin, then this book is for you. To easily grasp the concepts in this book, a basic understanding of Kotlin, or experience in a similar programming language is a must.
Author(s): Alex Forrester, Eran Boudjnah, Alexandru Dumbravan, Jomar Tigcal
Edition: 2
Publisher: Packt Publishing
Year: 2023
Language: English
Commentary: Publisher's PDF
Pages: 704
City: Birmingham, UK
Tags: Google Maps; Animation; Android; Application Development; Unit Testing; User Interface; Coroutines; Software Architecture; Integration Testing; Testing; Kotlin; Dependency Injection; RxJava; Google Play; Mobile Applications; Data Persistence; Material Design
Cover
Title Page
Copyright
Dedication
Contributors
Table of Contents
Preface
Part 1: Android Foundation
Chapter 1: Creating Your First App
Technical requirements
Creating an Android project with Android Studio
Exercise 1.01 – creating an Android Studio project for your app
Setting up a virtual device and running your app
Exercise 1.02 – setting up a virtual device and running your app on it
The Android manifest
Exercise 1.03 – configuring the Android manifest internet permission
Using Gradle to build, configure, and manage app dependencies
The project-level build.gradle file
The app-level build.gradle file
Exercise 1.04 – exploring how Material Design is used to theme an app
Android application structure
Exercise 1.05 – adding interactive UI elements to display a bespoke greeting to the user
Accessing Views in layout files
Further input validation
Activity 1.01 – producing an app to create RGB colors
Summary
Chapter 2: Building User Screen Flows
Technical requirements
The Activity lifecycle
Exercise 2.01 – logging the Activity Callbacks
Saving and restoring the Activity state
Exercise 2.02 – saving and restoring the state in layouts
Exercise 2.03 – saving and restoring the state with Callbacks
Activity interaction with Intents
Exercise 2.04 – an introduction to Intents
Exercise 2.05 – retrieving a result from an Activity
Intents, Tasks, and Launch Modes
Exercise 2.06 – setting the Launch Mode of an Activity
Activity 2.01 – creating a login form
Summary
Chapter 3: Developing the UI with Fragments
Technical requirements
The fragment lifecycle
onAttach
onCreate
onCreateView
onViewCreated
onActivityCreated
onStart
onResume
onPause
onStop
onDestroyView
onDestroy
onDetach
Exercise 3.01 – adding a basic fragment and the fragment lifecycle
Exercise 3.02 – adding fragments statically to an activity
Static fragments and dual-pane layouts
Exercise 3.03 – dual-pane layouts with static fragments
Dynamic fragments
Exercise 3.04 – adding fragments dynamically to an activity
Jetpack Navigation
Exercise 3.05 – adding a Jetpack navigation graph
Activity 3.01 – creating a quiz on the planets
Summary
Chapter 4: Building App Navigation
Technical requirements
Navigation overview
Navigation drawer
Exercise 4.01 – creating an App with a navigation drawer
Bottom navigation
Exercise 4.02 – adding bottom navigation to your app
Tabbed navigation
Exercise 4.03 – using tabs for app navigation
Activity 4.01 – building primary and secondary app navigation
Summary
Part 2: Displaying Network Calls
Chapter 5: Essential Libraries: Retrofit, Moshi, and Glide
Technical requirements
Introducing REST, API, JSON, and XML
Fetching data from a network endpoint
Exercise 5.01 – reading data from an API
Parsing a JSON response
Exercise 5.02 – extracting the image URL from the API response
Loading images from a remote URL
Exercise 5.03 – loading the image from the obtained URL
Activity 5.01 – displaying the current weather
Summary
Chapter 6: Adding and Interacting with RecyclerView
Technical requirements
Adding RecyclerView to our layout
Exercise 6.01 – adding an empty RecyclerView to your main activity
Populating RecyclerView
Exercise 6.02 – populating your RecyclerView
Responding to clicks in RecyclerView
Exercise 6.03 – responding to clicks
Supporting different Item types
Exercise 6.04 – adding titles to RecyclerView
Swiping to remove Items
Exercise 6.05 – adding swipe to delete functionality
Adding items interactively
Exercise 6.06 – implementing an Add A Cat button
Activity 6.01 – managing a list of Items
Summary
Chapter 7: Android Permissions and Google Maps
Technical requirements
Requesting permission from the user
Exercise 7.01 – requesting the location permission
Showing a map of the user’s location
Exercise 7.02 – obtaining the user’s current location
Map clicks and custom markers
Exercise 7.03 – adding a custom marker where the map was clicked
Activity 7.01 – creating an app to find the location of a parked car
Summary
Chapter 8: Services, WorkManager, and Notifications
Technical requirements
Starting a background task using WorkManager
Exercise 8.01 – executing background work with the WorkManager class
Background operations noticeable to the user – using a Foreground Service
Exercise 8.02 – tracking your SCA’s work with a Foreground Service
Activity 8.01 – reminder to drink water
Summary
Chapter 9: Building User Interfaces Using Jetpack Compose
Technical requirements
What is Jetpack Compose?
Exercise 9.01 – first Compose screen
Handling user actions
Exercise 9.02 – handling user inputs
Theming in Compose
Exercise 9.03 – applying themes
Adding Compose to existing projects
Activity 9.01 – first Compose app
Summary
Part 3: Testing and Code Structure
Chapter 10: Unit Tests and Integration Tests with JUnit, Mockito, and Espresso
Technical requirements
Types of testing
JUnit
Android Studio testing tips
Mockito
Exercise 10.01 – testing the sum of numbers
Integration tests
Robolectric
Espresso
Exercise 10.02 – double integration
UI tests
Testing in Jetpack Compose
Exercise 10.03 – random waiting times
TDD
Exercise 10.04 – using TDD to calculate the sum of numbers
Activity 10.01 – developing with TDD
Summary
Chapter 11: Android Architecture Components
Technical requirements
Android components background
ViewModel
Exercise 11.01 – shared ViewModel
Data streams
LiveData
Additional data streams
Room
Entities
DAO
Setting up the database
Third-party frameworks
Exercise 11.03 – making a little room
Activity 11.01 – a shopping notes app
Summary
Chapter 12: Persisting Data
Technical requirements
Preferences and DataStore
SharedPreferences
Exercise 12.01 – wrapping SharedPreferences
DataStore
Exercise 12.02 – Preference DataStore
Files
Internal storage
External storage
FileProvider
The Storage Access Framework (SAF)
Asset files
Exercise 12.03 – copying files
Scoped storage
Camera and media storage
Exercise 12.04 – taking photos
Activity 12.01 – dog downloader
Summary
Chapter 13: Dependency Injection with Dagger, Hilt, and Koin
Technical requirements
The necessity of dependency injection
Manual DI
Exercise 13.01 – manual injection
Dagger 2
Consumers
Providers
Connectors
Qualifiers
Scopes
Subcomponents
Exercise 13.02 – Dagger injection
Hilt
Exercise 13.03 – Hilt injection
Koin
Exercise 13.04 – Koin injection
Activity 13.01 – injected repositories
Summary
Part 4: Polishing and Publishing an App
Chapter 14: Coroutines and Flow
Technical requirements
Using Coroutines on Android
Creating coroutines
Adding coroutines to your project
Exercise 14.01 – using coroutines in an Android app
Transforming LiveData
Exercise 14.02 – LiveData transformations
Using Flow on Android
Collecting Flows on Android
Creating Flows with Flow Builders
Using operators with Flows
Exercise 14.03 – using Flow in an Android application
Activity 14.01 – creating a TV Guide app
Summary
Chapter 15: Architecture Patterns
Technical requirements
Getting started with MVVM
Binding data on Android with data binding
Exercise 15.01– using data binding in an Android project
Using Retrofit and Moshi
Implementing the Repository pattern
Exercise 15.02 – using Repository with Room in an Android project
Using WorkManager
Exercise 15.03 – adding WorkManager to an Android Project
Activity 15.01 – revisiting the TV Guide app
Summary
Chapter 16: Animations and Transitions with CoordinatorLayout and MotionLayout
Technical requirements
Activity transitions
Adding activity transitions through XML
Adding activity transitions through code
Starting an activity with an activity transition
Exercise 16.01 – creating activity transitions in an app
Adding a shared element transition
Starting an activity with the shared element transition
Exercise 16.02 – creating the shared element transition
Animations with CoordinatorLayout
Animations with MotionLayout
Adding MotionLayout
Creating animations with MotionLayout
Exercise 16.03 – adding animations with MotionLayout
The Motion Editor
Debugging MotionLayout
Modifying the MotionLayout path
Exercise 16.04 – modifying the animation path with keyframes
Activity 16.01 – Password Generator
Summary
Chapter 17: Launching Your App on Google Play
Preparing your apps for release
Versioning apps
Creating a keystore
Exercise 17.01 – creating a keystore in Android Studio
Storing the keystore and passwords
Signing your apps for release
Exercise 17.02 – creating a signed APK
Android app bundle
Exercise 17.03 – creating a signed app bundle
App signing by Google Play
Creating a developer account
Uploading an app to Google Play
Creating a store listing
Preparing the release
Rolling out a release
Managing app releases
Release tracks
Staged rollouts
Managed publishing
Activity 17.01 – publishing an app
Summary
Index
About Packt
Other Books You May Enjoy