Saving Data on Android

Learn about different ways to save data on Android! Use SharedPreferences to store user-facing configuration, use Files to store complex data in the form of JSON or media files, and use the SQLite Open Helper database to store meaningful objects that you can create, read, update and delete. By Filip Babić.

3.1 (12) · 5 Reviews

Save for later
Comments
Share

Learning path

This is part of the Android Data & Networking learning path. View path.

Who is this for?

All beginner and intermediate Android developers who are looking for ways to store their data locally, support offline mode, or to save data without having to use a remote server.

Covered concepts

  • Local Persistence
  • SharedPreferences
  • File System
  • Data Streams
  • Internal Storage
  • External Storage
  • Gson
  • Media Files
  • Scoped Storage
  • SQL
  • Primary Keys
  • SQLite Open Helper
  • Queries
  • ContentValues
  • Cursors
  • Database Migrations

Part 1: Store Data In Shared Preferences

01
Toggle description

Welcome to the Saving Data on Android course! Learn about the concepts of data persistence on Android, what each concept brings, and how they are different.

Toggle description

Explore the starter project you'll be working on in the course, and set up your developer environment.

Toggle description

Learn how to use Context objects from Android to create SharedPreferences that are private to your app.

Toggle description

Learn about the SharedPreferences editors, and how to use them to store data, using commit() and apply() functions.

Toggle description

Practice using SharedPreferences to add functions which read the data from Prefs and show it to the user.

Toggle description

Learn about local, activity-based preferences, which are unique to Activity classes, and cannot be accessed globally.

Conclusion 3:03
Toggle description

Review all the concepts you've learned about SharedPreferences and storing simple user-facing configuration options.

Part 2: Use The File System

Toggle description

Learn about the File System in Android, what Files are used for, data streams, and how to write or read Files.

Toggle description

Set up some of the basic file operations that will help you access and work with the File System.

Save Files 4:02
Toggle description

Learn how to store data in Files, and how to translate data into JSON structures, using Gson.

Read Files 1:53
Toggle description

Learn how to read files, and how to list out all the files in the root or parent directory.

Toggle description

Practice using Files by adding more operations to your FilesHelper, and by connecting them to the UI.

Toggle description

Learn how to switch to the external storage, to be able to expose your files to other applications.

Toggle description

Learn about Scoped Storage, the new way of storing and securing files on Android, and how to migrate.

Conclusion 2:26
Toggle description

Review all the concepts you've learned so far, and prepare for the last part of the course, and using databases.

Part 3: Use SQLite Database

Toggle description

Learn about the last concept in data persistence in the course - databases. Learn what SQL is and how SQL databases are formed.

Toggle description

Prepare the basic files and operations for your SQLiteOpenHelper database, and future episodes.

Toggle description

Learn how to save data in the database, by using ContentValues and writable databases. Explore the data using DBBS.

Toggle description

Learn how to read data from the database, using cursors. Display the data in the UI.

Toggle description

Practice using the SQLiteOpenHelper and its functions, to add more queries to your database.

Toggle description

Learn what database migrations are, and how to use them to add columns to the database and change the schema.

Toggle description

Finish your database implementation, by adding the final database query, to update trips with locations.

Conclusion 2:39
Toggle description

Congrats on finishing the course! Review all the concepts you've learned so far, and learn about new courses and more content to watch, to expand your knowledge.

Up next

Android & Kotlin
Kotlin Coroutines: Fundamentals
Learn the fundamentals about threads and coroutines, along with the basics of the Kotlin Coroutines framew... more

Instructors

Contributors

Filip Babić

Instructor

Christine Sweigart

Editor

Adriana Kutenko

Illustrator

Over 300 content creators. Join our team.