Chapters

Hide chapters

Saving Data on Android

Second Edition · Android 11 · Kotlin 1.5 · Android Studio 4.2

Using Firebase

Section 3: 11 chapters
Show chapters Hide chapters

Welcome to the Second Edition of Saving Data on Android, completely updated for Kotlin 1.5 and Android Studio 4.2!

Kotlin has been improved a lot for the past few years. It also has been announced as Google’s preferred programming language for Android developers. Since then, Kotlin becomes more popular with each new day and one of the main reasons is its simplicity.

Saving Data on Android explains how to use Kotlin to manage data persistence in your app. Once you read this book, you won’t ever doubt how to store your app’s data.

The most important part is to learn how to avoid cluttering app storage. If you’re dealing with sensitive and unique content, you’ll find out how to store data in a safe environment as well. Since the last book version, there are some new tools launched to our Android world, and this book covers them as well. Lucky you!

In this book, you’ll learn everything about saving data possibilities. You’ll start with simple data persistence mechanisms — managing data using files, storing a small amount of data in form of key—value pairs, creating SQLite type of database and manipulating data in it using queries. You’ll find out how to share stored data across more clients and what is the new and improved version of storing key—value pairs delivered by Google.

Once you learn the basics, you’ll find out how to create a Room database that can contain more complex data and in which way you can store, retrieve, update and delete data from it.

Finally, you’ll meet some options of storing data remotely.

These chapters include several plain code blocks what makes simultaneous reading and coding pretty easy. This also means you’ll have a bunch of room for experimenting. With a lot of practice, this book will make you an expert on data persistence!

How to read this book

In this book, every chapter contains theory about the specific topic and a simple practical task to learn implementation faster.

Each section is based on a certain type of data persistence. Also, there are three awesome applications you’ll develop — each one per section.

To learn and notice every little detail, read chapters in order. However, this book is for advanced users and there is a possibility you want to skip some chapters. In that case, be sure to continue from the starter project of the chapter you are moving to. The starter projects contain all steps implemented in the previous chapters of a certain section.

Assuming you have some experience in Android, all code used in this book is written in Kotlin and applications are built-in Android Studio.

While going through the chapter, you can type the code in Android Studio immediately. Feel free to play with the code and investigate the references provided in the chapter. Also, in the first section we prepared one fun challenge for you to test how much you learned. :]

This book is split into 3 main sections:

Section I: Saving Data Using Android SDK and Jetpack DataStore

Managing persistence is one of the main features that every mobile environment should provide, and Android is no different. In this chapter, you’ll learn, through practical examples, how to use the API that Android SDK provides to persist data. You’ll learn when and how to manage persistence depending on the type and quantity of data. The main focus will be on storing data to Files, SharedPreferences and SQLite Database. You’ll also learn how to share data across multiple applications with ContentProvider. At the end of the section, you’ll get familiar with Google’s latest tool for handling data persistence —Jetpack DataStore — and how to migrate from SharedPreferences to it.

Section II: Using Room

At Google I/O 2018, Google presented a set of new components for Android development with the name of Architecture Components. The goal was to provide a set of solutions for the most common problem in the development of Android applications. The solution for persistence is Room which is the topic of this section. You’ll learn how to use this library in the most common scenarios. Also, this section includes steps on how to safely migrate data once database schema changes.

Section III: Using Firebase

Firebase is a mature suite of products that allow you to implement Android applications that persist information in a safe, secure and reliable way. In this section, you’ll learn the fundamentals and more advanced concepts of Firebase, including how to read and write to Realtime Database, how to use it in offline mode, as well as its usage and performance. You’ll learn a few things about managing and securing data in Cloud Firestore. The last part of the section contains basic about Cloud Storage.

It’s always the right time to explore data persistence possibilities. Are you ready to dive into it? :]

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2024 Kodeco Inc.