Chapter 7. Persistence
The persistence of data allows an app to form what might appear to be a memory. There are a number of ways to accomplish this within mobile software development, but the most common is through the use of a relational database. From the start Android and iOS have had the ability to connect, read, and write to databases.
The result of this is that a user’s session within an app is no longer an ephemeral existence, but one that is anchored to a point in time. Data can be stored, information can be saved, and state can be restored. Through very different architectures and approaches, there is a shared set of functionality that powers both Android and iOS in a way that makes it similar enough to discuss side by side.
Tasks
In this chapter, you’ll learn to:
-
Establish a database connection.
-
Create a database table or persistent object.
-
Write data to that table or persistent object.
-
Read data from that table or persistent object.
Android
In Android, the framework-provided database management system is SQLite. The exact version depends on the Android OS level, but at the time of this writing it ranges from 3.4 in Android 1 to 3.19 in Android 27. See Android’s developer documentation for up-to-date information.
SQLite is a SQL-based relational database management system (DBMS) and is very similar to MySQL and PostgreSQL. There are differences, in datatypes, functions, and implementation details for things like ALTER TABLE
, but they’re still very similar, ...
Get Native Mobile Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.