Android Studio Electric Eel Essentials - Kotlin Edition: Developing Android Apps Using Android Studio 2022.1.1 and Kotlin

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Fully updated for Android Studio Electric Eel, this book aims to teach you how to develop Android-based applications using the Kotlin programming language.

This book begins with the basics and outlines the steps necessary to set up an Android development and testing environment followed by an introduction to programming in Kotlin, including data types, control flow, functions, lambdas, and object-oriented programming. Asynchronous programming using Kotlin coroutines and flow is also covered in detail.

An overview of Android Studio is included covering areas such as tool windows, the code editor, and the Layout Editor tool. An introduction to the architecture of Android is followed by an in-depth look at the design of Android applications and user interfaces using the Android Studio environment.

Chapters are also included covering the Android Architecture Components including view models, lifecycle management, Room database access, the Database Inspector, app navigation, live data, and data binding.

More advanced topics such as intents are also covered, as are touch screen handling, gesture recognition, and the recording and playback of audio. This edition of the book also covers printing, transitions, and foldable device support.

The concepts of material design are also covered in detail, including the use of floating action buttons, Snackbars, tabbed interfaces, card views, navigation drawers, and collapsing toolbars.

Other key features of Android Studio and Android are also covered in detail, including the Layout Editor, the ConstraintLayout and ConstraintSet classes, MotionLayout Editor, view binding, constraint chains, barriers, and direct reply notifications.

Chapters also cover advanced features of Android Studio, such as App Links, Dynamic Delivery, Gradle build configuration, in-app billing, and submitting apps to the Google Play Developer Console.

Assuming you already have some programming experience, are ready to download Android Studio and the Android SDK, have access to a Windows, Mac, or Linux system, and have ideas for some apps to develop, you are ready to get started.

Author(s): Neil Smyth
Edition: 1
Publisher: Payload Media
Year: 2023

Language: English
Pages: 828
City: North Carolina
Tags: Kotlin Programming; Mobile App Development; Android Studio; Electric Eel; Android

1. Introduction
1.1 Downloading the Code Samples
1.2 Feedback
1.3 Errata
2. Setting up an Android Studio Development Environment
2.1 System requirements
2.2 Downloading the Android Studio package
2.3 Installing Android Studio
2.3.1 Installation on Windows
2.3.2 Installation on macOS
2.3.3 Installation on Linux
2.4 The Android Studio setup wizard
2.5 Installing additional Android SDK packages
2.6 Installing the Android SDK Command-line Tools
2.6.1 Windows 8.1
2.6.2 Windows 10
2.6.3 Windows 11
2.6.4 Linux
2.6.5 macOS
2.7 Android Studio memory management
2.8 Updating Android Studio and the SDK
2.9 Summary
3. Creating an Example Android App in Android Studio
3.1 About the Project
3.2 Creating a New Android Project
3.3 Creating an Activity
3.4 Defining the Project and SDK Settings
3.5 Modifying the Example Application
3.6 Modifying the User Interface
3.7 Reviewing the Layout and Resource Files
3.8 Adding the Kotlin Extensions Plugin
3.9 Adding Interaction
3.10 Summary
4. Creating an Android Virtual Device (AVD) in Android Studio
4.1 About Android Virtual Devices
4.2 Starting the Emulator
4.3 Running the Application in the AVD
4.4 Running on Multiple Devices
4.5 Stopping a Running Application
4.6 Supporting Dark Theme
4.7 Running the Emulator in a Separate Window
4.8 Enabling the Device Frame
4.9 AVD Command-line Creation
4.10 Android Virtual Device Configuration Files
4.11 Moving and Renaming an Android Virtual Device
4.12 Summary
5. Using and Configuring the Android Studio AVD Emulator
5.1 The Emulator Environment
5.2 Emulator Toolbar Options
5.3 Working in Zoom Mode
5.4 Resizing the Emulator Window
5.5 Extended Control Options
5.5.1 Location
5.5.2 Displays
5.5.3 Cellular
5.5.4 Battery
5.5.5 Camera
5.5.6 Phone
5.5.7 Directional Pad
5.5.8 Microphone
5.5.9 Fingerprint
5.5.10 Virtual Sensors
5.5.11 Snapshots
5.5.12 Record and Playback
5.5.13 Google Play
5.5.14 Settings
5.5.15 Help
5.6 Working with Snapshots
5.7 Configuring Fingerprint Emulation
5.8 The Emulator in Tool Window Mode
5.9 Creating a Resizable Emulator
5.10 Summary
6. A Tour of the Android Studio User Interface
6.1 The Welcome Screen
6.2 The Main Window
6.3 The Tool Windows
6.4 Android Studio Keyboard Shortcuts
6.5 Switcher and Recent Files Navigation
6.6 Changing the Android Studio Theme
6.7 Summary
7. Testing Android Studio Apps on a Physical Android Device
7.1 An Overview of the Android Debug Bridge (ADB)
7.2 Enabling USB Debugging ADB on Android Devices
7.2.1 macOS ADB Configuration
7.2.2 Windows ADB Configuration
7.2.3 Linux adb Configuration
7.3 Resolving USB Connection Issues
7.4 Enabling Wireless Debugging on Android Devices
7.5 Testing the adb Connection
7.6 Device Mirroring
7.7 Summary
8. The Basics of the Android Studio Code Editor
8.1 The Android Studio Editor
8.2 Splitting the Editor Window
8.3 Code Completion
8.4 Statement Completion
8.5 Parameter Information
8.6 Parameter Name Hints
8.7 Code Generation
8.8 Code Folding
8.9 Quick Documentation Lookup
8.10 Code Reformatting
8.11 Finding Sample Code
8.12 Live Templates
8.13 Summary
9. An Overview of the Android Architecture
9.1 The Android Software Stack
9.2 The Linux Kernel
9.3 Android Runtime – ART
9.4 Android Libraries
9.4.1 C/C++ Libraries
9.5 Application Framework
9.6 Applications
9.7 Summary
10. The Anatomy of an Android Application
10.1 Android Activities
10.2 Android Fragments
10.3 Android Intents
10.4 Broadcast Intents
10.5 Broadcast Receivers
10.6 Android Services
10.7 Content Providers
10.8 The Application Manifest
10.9 Application Resources
10.10 Application Context
10.11 Summary
11. An Introduction to Kotlin
11.1 What is Kotlin?
11.2 Kotlin and Java
11.3 Converting from Java to Kotlin
11.4 Kotlin and Android Studio
11.5 Experimenting with Kotlin
11.6 Semi-colons in Kotlin
11.7 Summary
12. Kotlin Data Types, Variables, and Nullability
12.1 Kotlin Data Types
12.1.1 Integer Data Types
12.1.2 Floating-Point Data Types
12.1.3 Boolean Data Type
12.1.4 Character Data Type
12.1.5 String Data Type
12.1.6 Escape Sequences
12.2 Mutable Variables
12.3 Immutable Variables
12.4 Declaring Mutable and Immutable Variables
12.5 Data Types are Objects
12.6 Type Annotations and Type Inference
12.7 Nullable Type
12.8 The Safe Call Operator
12.9 Not-Null Assertion
12.10 Nullable Types and the let Function
12.11 Late Initialization (lateinit)
12.12 The Elvis Operator
12.13 Type Casting and Type Checking
12.14 Summary
13. Kotlin Operators and Expressions
13.1 Expression Syntax in Kotlin
13.2 The Basic Assignment Operator
13.3 Kotlin Arithmetic Operators
13.4 Augmented Assignment Operators
13.5 Increment and Decrement Operators
13.6 Equality Operators
13.7 Boolean Logical Operators
13.8 Range Operator
13.9 Bitwise Operators
13.9.1 Bitwise Inversion
13.9.2 Bitwise AND
13.9.3 Bitwise OR
13.9.4 Bitwise XOR
13.9.5 Bitwise Left Shift
13.9.6 Bitwise Right Shift
13.10 Summary
14. Kotlin Control Flow
14.1 Looping Control flow
14.1.1 The Kotlin for-in Statement
14.1.2 The while Loop
14.1.3 The do ... while loop
14.1.4 Breaking from Loops
14.1.5 The continue Statement
14.1.6 Break and Continue Labels
14.2 Conditional Control Flow
14.2.1 Using the if Expressions
14.2.2 Using if ... else … Expressions
14.2.3 Using if ... else if ... Expressions
14.2.4 Using the when Statement
14.3 Summary
15. An Overview of Kotlin Functions and Lambdas
15.1 What is a Function?
15.2 How to Declare a Kotlin Function
15.3 Calling a Kotlin Function
15.4 Single Expression Functions
15.5 Local Functions
15.6 Handling Return Values
15.7 Declaring Default Function Parameters
15.8 Variable Number of Function Parameters
15.9 Lambda Expressions
15.10 Higher-order Functions
15.11 Summary
16. The Basics of Object Oriented Programming in Kotlin
16.1 What is an Object?
16.2 What is a Class?
16.3 Declaring a Kotlin Class
16.4 Adding Properties to a Class
16.5 Defining Methods
16.6 Declaring and Initializing a Class Instance
16.7 Primary and Secondary Constructors
16.8 Initializer Blocks
16.9 Calling Methods and Accessing Properties
16.10 Custom Accessors
16.11 Nested and Inner Classes
16.12 Companion Objects
16.13 Summary
17. An Introduction to Kotlin Inheritance and Subclassing
17.1 Inheritance, Classes and Subclasses
17.2 Subclassing Syntax
17.3 A Kotlin Inheritance Example
17.4 Extending the Functionality of a Subclass
17.5 Overriding Inherited Methods
17.6 Adding a Custom Secondary Constructor
17.7 Using the SavingsAccount Class
17.8 Summary
18. An Overview of Android View Binding
18.1 Find View by Id and Synthetic Properties
18.2 View Binding
18.3 Converting the AndroidSample project
18.4 Enabling View Binding
18.5 Using View Binding
18.6 Choosing an Option
18.7 View Binding in the Book Examples
18.8 Migrating a Project to View Binding
18.9 Summary
19. Understanding Android Application and Activity Lifecycles
19.1 Android Applications and Resource Management
19.2 Android Process States
19.2.1 Foreground Process
19.2.2 Visible Process
19.2.3 Service Process
19.2.4 Background Process
19.2.5 Empty Process
19.3 Inter-Process Dependencies
19.4 The Activity Lifecycle
19.5 The Activity Stack
19.6 Activity States
19.7 Configuration Changes
19.8 Handling State Change
19.9 Summary
20. Handling Android Activity State Changes
20.1 New vs. Old Lifecycle Techniques
20.2 The Activity and Fragment Classes
20.3 Dynamic State vs. Persistent State
20.4 The Android Lifecycle Methods
20.5 Lifetimes
20.6 Foldable Devices and Multi-Resume
20.7 Disabling Configuration Change Restarts
20.8 Lifecycle Method Limitations
20.9 Summary
21. Android Activity State Changes by Example
21.1 Creating the State Change Example Project
21.2 Designing the User Interface
21.3 Overriding the Activity Lifecycle Methods
21.4 Filtering the Logcat Panel
21.5 Running the Application
21.6 Experimenting with the Activity
21.7 Summary
22. Saving and Restoring the State of an Android Activity
22.1 Saving Dynamic State
22.2 Default Saving of User Interface State
22.3 The Bundle Class
22.4 Saving the State
22.5 Restoring the State
22.6 Testing the Application
22.7 Summary
23. Understanding Android Views, View Groups and Layouts
23.1 Designing for Different Android Devices
23.2 Views and View Groups
23.3 Android Layout Managers
23.4 The View Hierarchy
23.5 Creating User Interfaces
23.6 Summary
24. A Guide to the Android Studio Layout Editor Tool
24.1 Basic vs. Empty Activity Templates
24.2 The Android Studio Layout Editor
24.3 Design Mode
24.4 The Palette
24.5 Design Mode and Layout Views
24.6 Night Mode
24.7 Code Mode
24.8 Split Mode
24.9 Setting Attributes
24.10 Transforms
24.11 Tools Visibility Toggles
24.12 Converting Views
24.13 Displaying Sample Data
24.14 Creating a Custom Device Definition
24.15 Changing the Current Device
24.16 Layout Validation
24.17 Summary
25. A Guide to the Android ConstraintLayout
25.1 How ConstraintLayout Works
25.1.1 Constraints
25.1.2 Margins
25.1.3 Opposing Constraints
25.1.4 Constraint Bias
25.1.5 Chains
25.1.6 Chain Styles
25.2 Baseline Alignment
25.3 Configuring Widget Dimensions
25.4 Guideline Helper
25.5 Group Helper
25.6 Barrier Helper
25.7 Flow Helper
25.8 Ratios
25.9 ConstraintLayout Advantages
25.10 ConstraintLayout Availability
25.11 Summary
26. A Guide to Using ConstraintLayout in Android Studio
26.1 Design and Layout Views
26.2 Autoconnect Mode
26.3 Inference Mode
26.4 Manipulating Constraints Manually
26.5 Adding Constraints in the Inspector
26.6 Viewing Constraints in the Attributes Window
26.7 Deleting Constraints
26.8 Adjusting Constraint Bias
26.9 Understanding ConstraintLayout Margins
26.10 The Importance of Opposing Constraints and Bias
26.11 Configuring Widget Dimensions
26.12 Design Time Tools Positioning
26.13 Adding Guidelines
26.14 Adding Barriers
26.15 Adding a Group
26.16 Working with the Flow Helper
26.17 Widget Group Alignment and Distribution
26.18 Converting other Layouts to ConstraintLayout
26.19 Summary
27. Working with ConstraintLayout Chains and Ratios in Android Studio
27.1 Creating a Chain
27.2 Changing the Chain Style
27.3 Spread Inside Chain Style
27.4 Packed Chain Style
27.5 Packed Chain Style with Bias
27.6 Weighted Chain
27.7 Working with Ratios
27.8 Summary
28. An Android Studio Layout Editor ConstraintLayout Tutorial
28.1 An Android Studio Layout Editor Tool Example
28.2 Creating a New Activity
28.3 Preparing the Layout Editor Environment
28.4 Adding the Widgets to the User Interface
28.5 Adding the Constraints
28.6 Testing the Layout
28.7 Using the Layout Inspector
28.8 Summary
29. Manual XML Layout Design in Android Studio
29.1 Manually Creating an XML Layout
29.2 Manual XML vs. Visual Layout Design
29.3 Summary
30. Managing Constraints using Constraint Sets
30.1 Kotlin Code vs. XML Layout Files
30.2 Creating Views
30.3 View Attributes
30.4 Constraint Sets
30.4.1 Establishing Connections
30.4.2 Applying Constraints to a Layout
30.4.3 Parent Constraint Connections
30.4.4 Sizing Constraints
30.4.5 Constraint Bias
30.4.6 Alignment Constraints
30.4.7 Copying and Applying Constraint Sets
30.4.8 ConstraintLayout Chains
30.4.9 Guidelines
30.4.10 Removing Constraints
30.4.11 Scaling
30.4.12 Rotation
30.5 Summary
31. An Android ConstraintSet Tutorial
31.1 Creating the Example Project in Android Studio
31.2 Adding Views to an Activity
31.3 Setting View Attributes
31.4 Creating View IDs
31.5 Configuring the Constraint Set
31.6 Adding the EditText View
31.7 Converting Density Independent Pixels (dp) to Pixels (px)
31.8 Summary
32. A Guide to using Apply Changes in Android Studio
32.1 Introducing Apply Changes
32.2 Understanding Apply Changes Options
32.3 Using Apply Changes
32.4 Configuring Apply Changes Fallback Settings
32.5 An Apply Changes Tutorial
32.6 Using Apply Code Changes
32.7 Using Apply Changes and Restart Activity
32.8 Using Run App
32.9 Summary
33. An Overview and Example of Android Event Handling
33.1 Understanding Android Events
33.2 Using the android:onClick Resource
33.3 Event Listeners and Callback Methods
33.4 An Event Handling Example
33.5 Designing the User Interface
33.6 The Event Listener and Callback Method
33.7 Consuming Events
33.8 Summary
34. Android Touch and Multi-touch Event Handling
34.1 Intercepting Touch Events
34.2 The MotionEvent Object
34.3 Understanding Touch Actions
34.4 Handling Multiple Touches
34.5 An Example Multi-Touch Application
34.6 Designing the Activity User Interface
34.7 Implementing the Touch Event Listener
34.8 Running the Example Application
34.9 Summary
35. Detecting Common Gestures Using the Android Gesture Detector Class
35.1 Implementing Common Gesture Detection
35.2 Creating an Example Gesture Detection Project
35.3 Implementing the Listener Class
35.4 Creating the GestureDetectorCompat Instance
35.5 Implementing the onTouchEvent() Method
35.6 Testing the Application
35.7 Summary
36. Implementing Custom Gesture and Pinch Recognition on Android
36.1 The Android Gesture Builder Application
36.2 The GestureOverlayView Class
36.3 Detecting Gestures
36.4 Identifying Specific Gestures
36.5 Installing and Running the Gesture Builder Application
36.6 Creating a Gestures File
36.7 Creating the Example Project
36.8 Extracting the Gestures File from the SD Card
36.9 Adding the Gestures File to the Project
36.10 Designing the User Interface
36.11 Loading the Gestures File
36.12 Registering the Event Listener
36.13 Implementing the onGesturePerformed Method
36.14 Testing the Application
36.15 Configuring the GestureOverlayView
36.16 Intercepting Gestures
36.17 Detecting Pinch Gestures
36.18 A Pinch Gesture Example Project
36.19 Summary
37. An Introduction to Android Fragments
37.1 What is a Fragment?
37.2 Creating a Fragment
37.3 Adding a Fragment to an Activity using the Layout XML File
37.4 Adding and Managing Fragments in Code
37.5 Handling Fragment Events
37.6 Implementing Fragment Communication
37.7 Summary
38. Using Fragments in Android Studio - An Example
38.1 About the Example Fragment Application
38.2 Creating the Example Project
38.3 Creating the First Fragment Layout
38.4 Migrating a Fragment to View Binding
38.5 Adding the Second Fragment
38.6 Adding the Fragments to the Activity
38.7 Making the Toolbar Fragment Talk to the Activity
38.8 Making the Activity Talk to the Text Fragment
38.9 Testing the Application
38.10 Summary
39. Modern Android App Architecture with Jetpack
39.1 What is Android Jetpack?
39.2 The “Old” Architecture
39.3 Modern Android Architecture
39.4 The ViewModel Component
39.5 The LiveData Component
39.6 ViewModel Saved State
39.7 LiveData and Data Binding
39.8 Android Lifecycles
39.9 Repository Modules
39.10 Summary
40. An Android Jetpack ViewModel Tutorial
40.1 About the Project
40.2 Creating the ViewModel Example Project
40.3 Reviewing the Project
40.3.1 The Main Activity
40.3.2 The Content Fragment
40.3.3 The ViewModel
40.4 Designing the Fragment Layout
40.5 Implementing the View Model
40.6 Associating the Fragment with the View Model
40.7 Modifying the Fragment
40.8 Accessing the ViewModel Data
40.9 Testing the Project
40.10 Summary
41. An Android Jetpack LiveData Tutorial
41.1 LiveData - A Recap
41.2 Adding LiveData to the ViewModel
41.3 Implementing the Observer
41.4 Summary
42. An Overview of Android Jetpack Data Binding
42.1 An Overview of Data Binding
42.2 The Key Components of Data Binding
42.2.1 The Project Build Configuration
42.2.2 The Data Binding Layout File
42.2.3 The Layout File Data Element
42.2.4 The Binding Classes
42.2.5 Data Binding Variable Configuration
42.2.6 Binding Expressions (One-Way)
42.2.7 Binding Expressions (Two-Way)
42.2.8 Event and Listener Bindings
42.3 Summary
43. An Android Jetpack Data Binding Tutorial
43.1 Removing the Redundant Code
43.2 Enabling Data Binding
43.3 Adding the Layout Element
43.4 Adding the Data Element to Layout File
43.5 Working with the Binding Class
43.6 Assigning the ViewModel Instance to the Data Binding Variable
43.7 Adding Binding Expressions
43.8 Adding the Conversion Method
43.9 Adding a Listener Binding
43.10 Testing the App
43.11 Summary
44. An Android ViewModel Saved State Tutorial
44.1 Understanding ViewModel State Saving
44.2 Implementing ViewModel State Saving
44.3 Saving and Restoring State
44.4 Adding Saved State Support to the ViewModelDemo Project
44.5 Summary
45. Working with Android Lifecycle-Aware Components
45.1 Lifecycle Awareness
45.2 Lifecycle Owners
45.3 Lifecycle Observers
45.4 Lifecycle States and Events
45.5 Summary
46. An Android Jetpack Lifecycle Awareness Tutorial
46.1 Creating the Example Lifecycle Project
46.2 Creating a Lifecycle Observer
46.3 Adding the Observer
46.4 Testing the Observer
46.5 Creating a Lifecycle Owner
46.6 Testing the Custom Lifecycle Owner
46.7 Summary
47. An Overview of the Navigation Architecture Component
47.1 Understanding Navigation
47.2 Declaring a Navigation Host
47.3 The Navigation Graph
47.4 Accessing the Navigation Controller
47.5 Triggering a Navigation Action
47.6 Passing Arguments
47.7 Summary
48. An Android Jetpack Navigation Component Tutorial
48.1 Creating the NavigationDemo Project
48.2 Adding Navigation to the Build Configuration
48.3 Creating the Navigation Graph Resource File
48.4 Declaring a Navigation Host
48.5 Adding Navigation Destinations
48.6 Designing the Destination Fragment Layouts
48.7 Adding an Action to the Navigation Graph
48.8 Implement the OnFragmentInteractionListener
48.9 Adding View Binding Support to the Destination Fragments
48.10 Triggering the Action
48.11 Passing Data Using Safeargs
48.12 Summary
49. An Introduction to MotionLayout
49.1 An Overview of MotionLayout
49.2 MotionLayout
49.3 MotionScene
49.4 Configuring ConstraintSets
49.5 Custom Attributes
49.6 Triggering an Animation
49.7 Arc Motion
49.8 Keyframes
49.8.1 Attribute Keyframes
49.8.2 Position Keyframes
49.9 Time Linearity
49.10 KeyTrigger
49.11 Cycle and Time Cycle Keyframes
49.12 Starting an Animation from Code
49.13 Summary
50. An Android MotionLayout Editor Tutorial
50.1 Creating the MotionLayoutDemo Project
50.2 ConstraintLayout to MotionLayout Conversion
50.3 Configuring Start and End Constraints
50.4 Previewing the MotionLayout Animation
50.5 Adding an OnClick Gesture
50.6 Adding an Attribute Keyframe to the Transition
50.7 Adding a CustomAttribute to a Transition
50.8 Adding Position Keyframes
50.9 Summary
51. A MotionLayout KeyCycle Tutorial
51.1 An Overview of Cycle Keyframes
51.2 Using the Cycle Editor
51.3 Creating the KeyCycleDemo Project
51.4 Configuring the Start and End Constraints
51.5 Creating the Cycles
51.6 Previewing the Animation
51.7 Adding the KeyFrameSet to the MotionScene
51.8 Summary
52. Working with the Floating Action Button and Snackbar
52.1 The Material Design
52.2 The Design Library
52.3 The Floating Action Button (FAB)
52.4 The Snackbar
52.5 Creating the Example Project
52.6 Reviewing the Project
52.7 Removing Navigation Features
52.8 Changing the Floating Action Button
52.9 Adding an Action to the Snackbar
52.10 Summary
53. Creating a Tabbed Interface using the TabLayout Component
53.1 An Introduction to the ViewPager2
53.2 An Overview of the TabLayout Component
53.3 Creating the TabLayoutDemo Project
53.4 Creating the First Fragment
53.5 Duplicating the Fragments
53.6 Adding the TabLayout and ViewPager2
53.7 Creating the Pager Adapter
53.8 Performing the Initialization Tasks
53.9 Testing the Application
53.10 Customizing the TabLayout
53.11 Summary
54. Working with the RecyclerView and CardView Widgets
54.1 An Overview of the RecyclerView
54.2 An Overview of the CardView
54.3 Summary
55. An Android RecyclerView and CardView Tutorial
55.1 Creating the CardDemo Project
55.2 Modifying the Basic Activity Project
55.3 Designing the CardView Layout
55.4 Adding the RecyclerView
55.5 Adding the Image Files
55.6 Creating the RecyclerView Adapter
55.7 Initializing the RecyclerView Component
55.8 Testing the Application
55.9 Responding to Card Selections
55.10 Summary
56. Working with the AppBar and Collapsing Toolbar Layouts
56.1 The Anatomy of an AppBar
56.2 The Example Project
56.3 Coordinating the RecyclerView and Toolbar
56.4 Introducing the Collapsing Toolbar Layout
56.5 Changing the Title and Scrim Color
56.6 Summary
57. An Overview of Android Intents
57.1 An Overview of Intents
57.2 Explicit Intents
57.3 Returning Data from an Activity
57.4 Implicit Intents
57.5 Using Intent Filters
57.6 Automatic Link Verification
57.7 Manually Enabling Links
57.8 Checking Intent Availability
57.9 Summary
58. Android Explicit Intents – A Worked Example
58.1 Creating the Explicit Intent Example Application
58.2 Designing the User Interface Layout for MainActivity
58.3 Creating the Second Activity Class
58.4 Designing the User Interface Layout for SecondActivity
58.5 Reviewing the Application Manifest File
58.6 Creating the Intent
58.7 Extracting Intent Data
58.8 Launching SecondActivity as a Sub-Activity
58.9 Returning Data from a Sub-Activity
58.10 Testing the Application
58.11 Summary
59. Android Implicit Intents – A Worked Example
59.1 Creating the Android Studio Implicit Intent Example Project
59.2 Designing the User Interface
59.3 Creating the Implicit Intent
59.4 Adding a Second Matching Activity
59.5 Adding the Web View to the UI
59.6 Obtaining the Intent URL
59.7 Modifying the MyWebView Project Manifest File
59.8 Installing the MyWebView Package on a Device
59.9 Testing the Application
59.10 Manually Enabling the Link
59.11 Automatic Link Verification
59.12 Summary
60. Android Broadcast Intents and Broadcast Receivers
60.1 An Overview of Broadcast Intents
60.2 An Overview of Broadcast Receivers
60.3 Obtaining Results from a Broadcast
60.4 Sticky Broadcast Intents
60.5 The Broadcast Intent Example
60.6 Creating the Example Application
60.7 Creating and Sending the Broadcast Intent
60.8 Creating the Broadcast Receiver
60.9 Registering the Broadcast Receiver
60.10 Testing the Broadcast Example
60.11 Listening for System Broadcasts
60.12 Summary
61. An Introduction to Kotlin Coroutines
61.1 What are Coroutines?
61.2 Threads vs Coroutines
61.3 Coroutine Scope
61.4 Suspend Functions
61.5 Coroutine Dispatchers
61.6 Coroutine Builders
61.7 Jobs
61.8 Coroutines – Suspending and Resuming
61.9 Returning Results from a Coroutine
61.10 Using withContext
61.11 Coroutine Channel Communication
61.12 Summary
62. An Android Kotlin Coroutines Tutorial
62.1 Creating the Coroutine Example Application
62.2 Adding Coroutine Support to the Project
62.3 Designing the User Interface
62.4 Implementing the SeekBar
62.5 Adding the Suspend Function
62.6 Implementing the launchCoroutines Method
62.7 Testing the App
62.8 Summary
63. An Overview of Android Services
63.1 Intent Service
63.2 Bound Service
63.3 The Anatomy of a Service
63.4 Controlling Destroyed Service Restart Options
63.5 Declaring a Service in the Manifest File
63.6 Starting a Service Running on System Startup
63.7 Summary
64. Android Local Bound Services – A Worked Example
64.1 Understanding Bound Services
64.2 Bound Service Interaction Options
64.3 A Local Bound Service Example
64.4 Adding a Bound Service to the Project
64.5 Implementing the Binder
64.6 Binding the Client to the Service
64.7 Completing the Example
64.8 Testing the Application
64.9 Summary
65. Android Remote Bound Services – A Worked Example
65.1 Client to Remote Service Communication
65.2 Creating the Example Application
65.3 Designing the User Interface
65.4 Implementing the Remote Bound Service
65.5 Configuring a Remote Service in the Manifest File
65.6 Launching and Binding to the Remote Service
65.7 Sending a Message to the Remote Service
65.8 Summary
66. An Introduction to Kotlin Flow
66.1 Understanding Flows
66.2 Creating the Sample Project
66.3 Adding the Kotlin Lifecycle Library
66.4 Declaring a Flow
66.5 Emitting Flow Data
66.6 Collecting Flow Data
66.7 Adding a Flow Buffer
66.8 Transforming Data with Intermediaries
66.9 Terminal Flow Operators
66.10 Flow Flattening
66.11 Combining Multiple Flows
66.12 Hot and Cold Flows
66.13 StateFlow
66.14 SharedFlow
66.15 Summary
67. An Android SharedFlow Tutorial
67.1 About the Project
67.2 Creating the SharedFlowDemo Project
67.3 Designing the User Interface Layout
67.4 Adding the List Row Layout
67.5 Adding the RecyclerView Adapter
67.6 Completing the ViewModel
67.7 Modifying the Main Fragment for View Binding
67.8 Collecting the Flow Values
67.9 Testing the SharedFlowDemo App
67.10 Handling Flows in the Background
67.11 Summary
68. An Overview of Android SQLite Databases
68.1 Understanding Database Tables
68.2 Introducing Database Schema
68.3 Columns and Data Types
68.4 Database Rows
68.5 Introducing Primary Keys
68.6 What is SQLite?
68.7 Structured Query Language (SQL)
68.8 Trying SQLite on an Android Virtual Device (AVD)
68.9 The Android Room Persistence Library
68.10 Summary
69. The Android Room Persistence Library
69.1 Revisiting Modern App Architecture
69.2 Key Elements of Room Database Persistence
69.2.1 Repository
69.2.2 Room Database
69.2.3 Data Access Object (DAO)
69.2.4 Entities
69.2.5 SQLite Database
69.3 Understanding Entities
69.4 Data Access Objects
69.5 The Room Database
69.6 The Repository
69.7 In-Memory Databases
69.8 Database Inspector
69.9 Summary
70. An Android TableLayout and TableRow Tutorial
70.1 The TableLayout and TableRow Layout Views
70.2 Creating the Room Database Project
70.3 Converting to a LinearLayout
70.4 Adding the TableLayout to the User Interface
70.5 Configuring the TableRows
70.6 Adding the Button Bar to the Layout
70.7 Adding the RecyclerView
70.8 Adjusting the Layout Margins
70.9 Summary
71. An Android Room Database and Repository Tutorial
71.1 About the RoomDemo Project
71.2 Modifying the Build Configuration
71.3 Building the Entity
71.4 Creating the Data Access Object
71.5 Adding the Room Database
71.6 Adding the Repository
71.7 Modifying the ViewModel
71.8 Creating the Product Item Layout
71.9 Adding the RecyclerView Adapter
71.10 Preparing the Main Fragment
71.11 Adding the Button Listeners
71.12 Adding LiveData Observers
71.13 Initializing the RecyclerView
71.14 Testing the RoomDemo App
71.15 Using the Database Inspector
71.16 Summary
72. Video Playback on Android using the VideoView and MediaController Classes
72.1 Introducing the Android VideoView Class
72.2 Introducing the Android MediaController Class
72.3 Creating the Video Playback Example
72.4 Designing the VideoPlayer Layout
72.5 Downloading the Video File
72.6 Configuring the VideoView
72.7 Adding the MediaController to the Video View
72.8 Setting up the onPreparedListener
72.9 Summary
73. Android Picture-in-Picture Mode
73.1 Picture-in-Picture Features
73.2 Enabling Picture-in-Picture Mode
73.3 Configuring Picture-in-Picture Parameters
73.4 Entering Picture-in-Picture Mode
73.5 Detecting Picture-in-Picture Mode Changes
73.6 Adding Picture-in-Picture Actions
73.7 Summary
74. An Android Picture-in-Picture Tutorial
74.1 Adding Picture-in-Picture Support to the Manifest
74.2 Adding a Picture-in-Picture Button
74.3 Entering Picture-in-Picture Mode
74.4 Detecting Picture-in-Picture Mode Changes
74.5 Adding a Broadcast Receiver
74.6 Adding the PiP Action
74.7 Testing the Picture-in-Picture Action
74.8 Summary
75. Making Runtime Permission Requests in Android
75.1 Understanding Normal and Dangerous Permissions
75.2 Creating the Permissions Example Project
75.3 Checking for a Permission
75.4 Requesting Permission at Runtime
75.5 Providing a Rationale for the Permission Request
75.6 Testing the Permissions App
75.7 Summary
76. Android Audio Recording and Playback using MediaPlayer and MediaRecorder
76.1 Playing Audio
76.2 Recording Audio and Video using the MediaRecorder Class
76.3 About the Example Project
76.4 Creating the AudioApp Project
76.5 Designing the User Interface
76.6 Checking for Microphone Availability
76.7 Initializing the Activity
76.8 Implementing the recordAudio() Method
76.9 Implementing the stopAudio() Method
76.10 Implementing the playAudio() method
76.11 Configuring and Requesting Permissions
76.12 Testing the Application
76.13 Summary
77. An Android Notifications Tutorial
77.1 An Overview of Notifications
77.2 Creating the NotifyDemo Project
77.3 Designing the User Interface
77.4 Creating the Second Activity
77.5 Creating a Notification Channel
77.6 Requesting Notification Permission
77.7 Creating and Issuing a Notification
77.8 Launching an Activity from a Notification
77.9 Adding Actions to a Notification
77.10 Bundled Notifications
77.11 Summary
78. An Android Direct Reply Notification Tutorial
78.1 Creating the DirectReply Project
78.2 Designing the User Interface
78.3 Requesting Notification Permission
78.4 Creating the Notification Channel
78.5 Building the RemoteInput Object
78.6 Creating the PendingIntent
78.7 Creating the Reply Action
78.8 Receiving Direct Reply Input
78.9 Updating the Notification
78.10 Summary
79. Printing with the Android Printing Framework
79.1 The Android Printing Architecture
79.2 The Print Service Plugins
79.3 Google Cloud Print
79.4 Printing to Google Drive
79.5 Save as PDF
79.6 Printing from Android Devices
79.7 Options for Building Print Support into Android Apps
79.7.1 Image Printing
79.7.2 Creating and Printing HTML Content
79.7.3 Printing a Web Page
79.7.4 Printing a Custom Document
79.8 Summary
80. An Android HTML and Web Content Printing Example
80.1 Creating the HTML Printing Example Application
80.2 Printing Dynamic HTML Content
80.3 Creating the Web Page Printing Example
80.4 Removing the Floating Action Button
80.5 Removing Navigation Features
80.6 Designing the User Interface Layout
80.7 Accessing the WebView from the Main Activity
80.8 Loading the Web Page into the WebView
80.9 Adding the Print Menu Option
80.10 Summary
81. A Guide to Android Custom Document Printing
81.1 An Overview of Android Custom Document Printing
81.1.1 Custom Print Adapters
81.2 Preparing the Custom Document Printing Project
81.3 Creating the Custom Print Adapter
81.4 Implementing the onLayout() Callback Method
81.5 Implementing the onWrite() Callback Method
81.6 Checking a Page is in Range
81.7 Drawing the Content on the Page Canvas
81.8 Starting the Print Job
81.9 Testing the Application
81.10 Summary
82. An Introduction to Android App Links
82.1 An Overview of Android App Links
82.2 App Link Intent Filters
82.3 Handling App Link Intents
82.4 Associating the App with a Website
82.5 Summary
83. An Android Studio App Links Tutorial
83.1 About the Example App
83.2 The Database Schema
83.3 Loading and Running the Project
83.4 Adding the URL Mapping
83.5 Adding the Intent Filter
83.6 Adding Intent Handling Code
83.7 Testing the App
83.8 Creating the Digital Asset Links File
83.9 Testing the App Link
83.10 Summary
84. An Android Biometric Authentication Tutorial
84.1 An Overview of Biometric Authentication
84.2 Creating the Biometric Authentication Project
84.3 Configuring Device Fingerprint Authentication
84.4 Adding the Biometric Permission to the Manifest File
84.5 Designing the User Interface
84.6 Adding a Toast Convenience Method
84.7 Checking the Security Settings
84.8 Configuring the Authentication Callbacks
84.9 Adding the CancellationSignal
84.10 Starting the Biometric Prompt
84.11 Testing the Project
84.12 Summary
85. Creating, Testing and Uploading an Android App Bundle
85.1 The Release Preparation Process
85.2 Android App Bundles
85.3 Register for a Google Play Developer Console Account
85.4 Configuring the App in the Console
85.5 Enabling Google Play App Signing
85.6 Creating a Keystore File
85.7 Creating the Android App Bundle
85.8 Generating Test APK Files
85.9 Uploading the App Bundle to the Google Play Developer Console
85.10 Exploring the App Bundle
85.11 Managing Testers
85.12 Rolling the App Out for Testing
85.13 Uploading New App Bundle Revisions
85.14 Analyzing the App Bundle File
85.15 Summary
86. An Overview of Android In-App Billing
86.1 Preparing a Project for In-App Purchasing
86.2 Creating In-App Products and Subscriptions
86.3 Billing Client Initialization
86.4 Connecting to the Google Play Billing Library
86.5 Querying Available Products
86.6 Starting the Purchase Process
86.7 Completing the Purchase
86.8 Querying Previous Purchases
86.9 Summary
87. An Android In-App Purchasing Tutorial
87.1 About the In-App Purchasing Example Project
87.2 Creating the InAppPurchase Project
87.3 Adding Libraries to the Project
87.4 Designing the User Interface
87.5 Adding the App to the Google Play Store
87.6 Creating an In-App Product
87.7 Enabling License Testers
87.8 Initializing the Billing Client
87.9 Querying the Product
87.10 Launching the Purchase Flow
87.11 Handling Purchase Updates
87.12 Consuming the Product
87.13 Restoring a Previous Purchase
87.14 Testing the App
87.15 Troubleshooting
87.16 Summary
88. An Overview of Android Dynamic Feature Modules
88.1 An Overview of Dynamic Feature Modules
88.2 Dynamic Feature Module Architecture
88.3 Creating a Dynamic Feature Module
88.4 Converting an Existing Module for Dynamic Delivery
88.5 Working with Dynamic Feature Modules
88.6 Handling Large Dynamic Feature Modules
88.7 Summary
89. An Android Studio Dynamic Feature Tutorial
89.1 Creating the DynamicFeature Project
89.2 Adding Dynamic Feature Support to the Project
89.3 Designing the Base Activity User Interface
89.4 Adding the Dynamic Feature Module
89.5 Reviewing the Dynamic Feature Module
89.6 Adding the Dynamic Feature Activity
89.7 Implementing the launchIntent() Method
89.8 Uploading the App Bundle for Testing
89.9 Implementing the installFeature() Method
89.10 Adding the Update Listener
89.11 Using Deferred Installation
89.12 Removing a Dynamic Module
89.13 Summary
90. Working with Material Design 3 Theming
90.1 Material Design 2 vs Material Design 3
90.2 Understanding Material Design Theming
90.3 Material Design 2 Theming
90.4 Material Design 3 Theming
90.5 Building a Custom Theme
90.6 Summary
91. A Material Design 3 Theming and Dynamic Color Tutorial
91.1 Creating the ThemeDemo Project
91.2 Preparing the Project
91.3 Designing the User Interface
91.4 Building a New Theme
91.5 Adding the Custom Colors to the Project
91.6 Merging the Custom Themes
91.7 Enabling Dynamic Color Support
91.8 Summary
92. Migrating from Material Design 2 to Material Design 3
92.1 Creating the ThemeMigration Project
92.2 Designing the User Interface
92.3 Migrating to Material Design 3
92.4 Building a New Theme
92.5 Adding the Theme to the Project
92.6 Summary
93. An Overview of Gradle in Android Studio
93.1 An Overview of Gradle
93.2 Gradle and Android Studio
93.2.1 Sensible Defaults
93.2.2 Dependencies
93.2.3 Build Variants
93.2.4 Manifest Entries
93.2.5 APK Signing
93.2.6 ProGuard Support
93.3 The Property and Settings Gradle Build File
93.4 The Top-level Gradle Build File
93.5 Module Level Gradle Build Files
93.6 Configuring Signing Settings in the Build File
93.7 Running Gradle Tasks from the Command-line
93.8 Summary
Index