INTRODUCTION xxxi CHAPTER 1: HELLO, ANDROID 1 Android Application Development 1 A Little Background 2 The Not-So-Distant Past 3 Living in the Future 3 The Android Ecosystem 3 Pre-installed Android Applications 4 Android SDK Features 5 What Does Android Run On? 6 Why Develop for Mobile? 6 Why Develop for Android? 7 Introducing the Development Framework 7 What Comes in the Box 8 Understanding the Android Software Stack 8 The Android Run Time 10 Android Application Architecture 11 Android Libraries 12 CHAPTER 2: GETTING STARTED 13 Getting Started Developing Android Apps 14 Developing for Android 15 What You Need to Begin 15 Creating Your First Android Application 20 Getting Started Writing Android Apps Using Kotlin 35 Using the Android Support Library Package 36 Developing for Mobile and Embedded Devices 39 Hardware-Imposed Design Considerations 39 Considering the User''s Environment 43 Developing for Android 44 Android Development Tools 48 Android Studio 49 The Android Virtual Device Manager 51 The Android Emulator 51 Android Profiler 52 The Android Debug Bridge 54 APK Analyzer 54 The Lint Tool 55 Monkey, Monkey Runner, and Espresso UI Testing 55 Gradle 56 CHAPTER 3: APPLICATIONS AND ACTIVITIES AND FRAGMENTS, OH MY! 57 Applications, Activities, and Fragments 58 The Components of an Android Application 58 The Android Application Life Cycle, Priority, and Process States 59 Introducing the Android Application Class 61 A Closer Look at Android Activities 61 Creating Activities 62 Using the AppCompatActivity 63 The Activity Life Cycle 64 Responding to Memory Pressure 71 Introducing Fragments 73 Creating New Fragments 73 The Fragment Life Cycle 74 Introducing the Fragment Manager 79 Adding Fragments to Activities 79 Communicating Between Fragments and Activities 85 Fragments without User Interfaces 86 Building an Earthquake Viewer Application 87 CHAPTER 4: DEFINING THE ANDROID MANIFEST AND GRADLE BUILD FILES, AND EXTERNALIZING RESOURCES 95 The Manifest, Build Files, and Resources 96 Introducing the Android Manifest 96 Configuring the Gradle Build 101 Gradle Settings File 101 Project Gradle Build File 102 Module Gradle Build Files 102 Externalizing Resources 107 Creating Resources 108 Using Resources 119 Creating Resources for Different Languages and Hardware 122 Runtime Configuration Changes 126 CHAPTER 5: BUILDING USER INTERFACES 129 Fundamental Android Design 130 Density-Independent Design 130 Android User Interface Fundamentals 131 Assigning User Interfaces to Activities 132 Introducing Layouts 132 Defining Layouts 134 Using Layouts to Create Device-Independent User Interfaces 136 Optimizing Layouts 139 The Android Widget Toolbox 143 Working with Lists and Grids 144 Recycler View and Layout Managers 145 Introducing Adapters 146 Returning to the Earthquake Viewer Application 149 Introducing Data Binding 150 Enabling Data Binding 151 Variables in Data Binding 152 Data Binding for the Earthquake Viewer Application 153 Creating New Views 155 Modifying Existing Views 155 Creating Compound Controls 159 Creating Simple Compound Controls as a Layout 161 Creating Custom Views 162 Using Custom Controls 176 CHAPTER 6: INTENTS AND BROADCAST RECEIVERS 177 Using Intents and Broadcast Receivers 178 Using Intents to Launch Activities 178 Explicitly Starting New Activities 179 Implicit Intents and Late Runtime Binding 179 Determining If an Intent Will Resolve 180 Returning Results from Activities 181 Using Platform-Native Actions to Launch Activities 184 Creating Intent Filters to Receive Implicit Intents 186 Defining an Intent Filter 186 Using Intent Filters for Plug-Ins and Extensibility 194 Introducing Linkify 198 Native Linkify Link Types 198 Creating Custom Link Strings 199 Using the Match Filter 200 Using the Transform Filter 200 Using Intents to Broadcast Events 200 Broadcasting Events with Intents 201 Listening for Intent Broadcasts with Broadcast Receivers 202 Registering Broadcast Receivers in Code 203 Registering Broadcast Receivers in Your Application Manifest 204 Managing Manifest Receivers at Run Time 204 Monitoring Device State Changes through Broadcast Intents 205 Introducing the Local Broadcast Manager 207 Introducing Pending Intents 208 CHAPTER 7: USING INTERNET RESOURCES 211 Connecting to the Internet 211 Connecting, Downloading, and Parsing Internet Resources 212 Why Build a Native Internet App? 212 Connecting to an Internet Resource 213 Performing Network Operations on Background Threads Using View Models, Live Data, and Asynchronous Tasks 214 Parsing XML Using the XML Pull Parser 219 Connecting the Earthquake Viewer to the Internet 220 Parsing JSON Using the JSON Parser 228 Using the Download Manager 233 Downloading Files 233 Customizing Download Manager Notifications 235 Specifying a Download Location 237 Canceling and Removing Downloads 238 Querying the Download Manager 238 Best Practices for Downloading Data without Draining the Battery 241 An Introduction to Internet Services and Cloud Computing 242 CHAPTER 8: FILES, SAVING STATE, AND USER PREFERENCES 245 Saving Files, States, and Preferences 246 Saving and Restoring Activity and Fragment Instance State Using the Lifecycle Handlers 246 Retaining Instance State with Headless Fragments and View Models 248 View Models and Live Data 248 Headless Fragments 251 Creating and Saving Shared Preferences 252 Retrieving Shared Preferences 253 Introducing On Shared Preference Change Listeners 254 Configuring Auto Backup of Application Files and Shared Preferences 254 Building a Preference UI 256 Using the Preference Support Library 256 Defining a Preference Screen Layout in XML 257 Introducing the Preference Fragment 260 Creating a Settings Activity for the Earthquake Monitor 261 Including Static Files as Resources 267 Working with the Filesystem 267 File-Management Tools 267 Creating Files on Application-Specifi c Internal Storage 268 Creating Files on Application-Specifi c External Storage 268 Accessing Public Directories Using Scoped Directory Access 270 Sharing Files Using File Provider 274 Creating a File Provider 274 Sharing a File Using a File Provider 275 Receiving a File from a File Provider 275 Accessing Files from Other Applications Using the Storage Access Framework 275 Requesting Temporary Access to Files 276 Requesting Persistent Access to Files 277 Requesting Access to Directories 277 Creating New Files 278 Using URI-Based Permissions 278 CHAPTER 9: CREATING AND USING DATABASES 281 Introducing Structured Data Storage in Android 282 Storing Data Using the Room Persistence Library 282 Adding the Room Persistence Library 283 Defining a Room Database 284 Persisting Complex Objects Using Type Convertors 286 Defining Room Database Interactions Using Data Access Objects 288 Performing Room Database Interactions 291 Monitoring Query Result Changes with Live Data 292 Persisting Earthquakes to a Database with Room 294 Working with SQLite Databases 298 Input Validation and SQL Injection 299 Cursors and Content Values 299 Defining a Database Contract 300 Introducing the SQLiteOpenHelper 300 Opening Databases with the SQLite Open Helper 302 Opening and Creating Databases without the SQLite Open Helper 303 Adding, Updating, and Deleting Rows 303 Querying a Database 305 Extracting Values from a Cursor 307 Introducing the Firebase Realtime Database 308 Adding Firebase to Your App 309 Defining a Firebase Database and Defining Access Rules 311 Adding, Modifying, Deleting, and Querying Data from a Firebase Realtime Database 313 CHAPTER 10: CONTENT PROVIDERS AND SEARCH 317 Introducing Content Providers 318 Why Should I Use Content Providers? 318 Creating Content Providers 319 Creating the Content Provider''s Database 320 Registering Content Providers 321 Publishing Your Content Provider''s URI Address 321 Implementing Content Provider Queries 322 Content Provider Transactions 325 Sharing Files Using a Content Provider 327 Adding Permission Requirements to Content Providers 328 Accessing Content Providers with Content Resolvers 330 Querying Content Providers 330 Cancelling Queries 333 Querying for Content Asynchronously with a Cursor Loader 333 Adding, Deleting, and Updating Content 336 Accessing Files Stored in Content Providers 338 Accessing Permission-Restricted Content Providers 339 Using Native Android Content Providers 341 Accessing the Call Log 341 Using the Media Store Content Provider 342 Using the Contacts Content Provider 344 Us.
Professional Android