Preface

The explosion in the number of mobile devices in all parts of the word has led to an increase in both the number and complexity of mobile apps. What was once considered a platform for only simplistic applications now contains countless apps with considerable functionality. Because a mobile device is capable of receiving large amounts of data from multiple data sources, there is an increasing need to store and recall that data efficiently.

In traditional software systems, large sets of data are frequently stored in a database that can be optimized to both store the data as well as recall the data on demand. Android provides this same functionality and includes a database system, SQLite. SQLite provides enough power to support today’s modern apps and also can perform well in the resource-constrained environment of most mobile devices. This book provides details on how to use the embedded Android database system. Additionally, the book contains advice inspired by problems encountered when writing “real-world” Android apps.

Who Should Read This Book

This book is written for developers who have at least some experience with writing Android apps. Specifically, an understanding of basic Android components (activities, fragments, intents, and the application manifest) is assumed, and familiarity with the Android threading model is helpful.

At least some knowledge of relational database systems is also helpful but is not necessarily a prerequisite for understanding the topics in this book.

How This Book Is Organized

This book begins with a discussion of the theory behind relational databases as well as some history of the relational model and how it came into existence. Next, the discussion moves to the Structured Query Language (SQL) and how to use SQL to build a database as well as manipulate and read a database. The discussion of SQL provides some details on Android specifics but generally discusses non-Android-specific SQL.

From there, the book moves on to provide information on SQLite and how it relates to Android. The book also covers the Android APIs that can be used to interact with a database as well as some best practices for database use.

With the basics of database, SQL, and SQLite covered, the book then moves into solving some of the problems app developers often face while using a database in Android. Topics such as threading, accessing remote data, and displaying data to the user are covered. Additionally, the book presents an example database access layer based on a content provider.

Following is an overview of each of the chapters:

Image Chapter 1, “Relational Databases,” provides an introduction to the relational database model as well as some information on why the relational model is more popular than older database models.

Image Chapter 2, “An Introduction to SQL,” provides details on SQL as it relates to databases in general. This chapter discusses the SQL language features for creating database structure as well as the features used to manipulate data in a database.

Image Chapter 3, “An Introduction to SQLite,” contains details of the SQLite database system, including how SQLite differs from other database systems.

Image Chapter 4, “SQLite in Android,” discusses the Android-specific SQLite details such as where a database resides for an app. It also discusses accessing a database from outside an app, which can be important for debugging.

Image Chapter 5, “Working with Databases in Android,” presents the Android API for working with databases and explains how to get data from an app to a database and back again.

Image Chapter 6, “Content Providers,” discusses the details around using a content provider as a data access mechanism in Android as well as some thoughts on when to use one.

Image Chapter 7, “Databases and the UI,” explains how to get data from the local database and display it to the user, taking into account some of the threading concerns that exist on Android.

Image Chapter 8, “Sharing Data with Intents,” discusses ways, other than using content providers, that data can be shared between apps, specifically by using intents.

Image Chapter 9, “Communicating with Web APIs,” discusses some of the methods and tools used to achieve two-way communication between an app and a remote Web API.

Image Chapter 10, “Data Binding,” discusses the data binding API and how it can be used to display data in the UI. In addition to providing an overview of the API, this chapter provides an example of how to view data from a database.

Example Code

This book includes a lot of source code examples, including an example app that is discussed in later chapters of the book. Readers are encouraged to download the example source code and manipulate it to gain a deeper understanding of the information presented in the text.

The example app is a Gradle-based Android project that should build and run. It was built with the latest libraries and build tools that were available at the time of this writing.

The source code for the example can be found on GitHub at https://github.com/android-database-best-practices/device-database. It is made available under the Apache 2 open-source license and can be used according to that license.

Conventions Used in This Book

The following typographical conventions are used in this book:

Image Constant width is used for program listings, as well as within paragraphs to refer to program elements such as variable and function names, databases, data types, environment variables, statements, and keywords.

Image Constant width bold is used to highlight sections of code.


Note

A Note signifies a tip, suggestion, or general note.



Register your copy of Android Database Best Practices at informit.com for convenient access to downloads, updates, and corrections as they become available. To start the registration process, go to informit.com/register and log in or create an account. Enter the product ISBN (9780134437996) and click Submit. Once the process is complete, you will find any available bonus content under “Registered Products.”


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.39.23