New Course: Saving Data on Android

Joe Howard

Saving Data on Android

It’s day 7 of the Android Avalanche: an event where we’ll be releasing new Android and Kotlin books, courses, and screencasts every day!

Today, we are releasing a brand new course: Saving Data on Android.

In this 32-video course by Joe Howard, you’ll learn how persist data on your Android apps between app restarts. Through a series of hands-on exercises and challenges, you’ll use SharedPreferences, read and write files to storage, save data using SQLite, and try out the new Room Library to save data!

Take a look at what’s inside:

Part 1: SharedPreferences

In part one, learn how save data using SharedPreferences.

  1. Introduction: Find out what’s covered in our Saving Data on Android video tutorial series: SharedPrefences, saving to files, SQLite, and Room.

  2. The Starter App: Download the starter app, build it in Android Studio, and review the existing app code. Review the Model-View-Presenter (MVP) and Repository patterns.

  3. Getting SharedPrefs: Learn about use cases for SharedPreferences, see how to access the default SharedPreferences, and also see how to setup a custom SharedPreferences.

  4. Reading and Writing SharedPrefs: Learn how to save data into SharedPreferences, and how to read the data back in.

  5. Challenge: Reading and Writing SharedPrefs: Practice what you’ve learned so far to save data into SharedPreferences and then read the data back in.

  6. SharedPrefs Repository: Switch from saving the app data from an in-memory repository into a repository backed by SharedPreferences. Learn about the limitations of SharedPreferences.

  7. Challenge: SharedPrefs Repository: Practice some more with the Repository pattern by deleting data from the SharedPreferences repository.

  8. Conclusion: Let’s review what you’ve covered on SharedPreferences and the Repository pattern in this first part on Saving Data on Android, and then discuss what’s next.

Part 2: Saving to Files

In the second part, learn to read and write files to storage.

  1. Introduction: We’ll survey various issues with writing files, including internal vs. external storage, permissions, thread concerns, and checking for disk space.

  2. Writing to Internal Storage: Learn how to write files to internal storage. You’ll use Gson to convert the app data and peer into the Android file system using Device File Explorer.

  3. Reading from Internal Storage: See how to read files from internal storage using the Java SDK FileInputStream and BufferedReader classes.

  4. Challenge: Internal Storage: Practice what you’ve learned about saving to internal storage by safeguarding your app against read and write errors.

  5. External Storage: Switch from using internal storage to external storage for saving the app data, and see how to use adb to pull files from a device.

  6. Deleting Files: Update the FileRepository to delete files, using some of the helper functions you’ve already developed.

  7. Challenge: Deleting Files: Finish the use of the FileRepository for saving app data by practicing what you’ve learned to delete files.

  8. Conclusion: Let’s review what you learned in this part of the course about saving data into files, reading files, and deleting files, and then discuss what’s next.

Part 3: SQLite

In part 3, you’ll learn how to save data using SQLite.

  1. Introduction: You are introduced to SQLite and the concepts of relational databases, including tables, columns, keys, and relationships.

  2. Creating a Database: Create a database schema and use SQLiteOpenHelper to create a basic database. See how to use sqlite3 at the command line to review the database schema.

  3. Writing Data: Use ContentValues as a means of writing data into SQLite. See how to use sqlite3 at the command line to query the database.

  4. Challenge: Writing Data: Practice what you’ve learned so far about SQLite and ContentValues to write data into the SQLite datbase.

  5. Reading Data: Use Cursor and and its companion CursorWrapper to read data from the SQLite database and into model objects.

  6. Deleting Data: See how to delete data from a SQLite database, and how to guard against SQL injection attacks in your SQL code.

  7. Challenge: Deleting Data: Finish the use of the SQLiteRepository for saving app data by practicing what you’ve learned to delete files.

  8. Database Migrations: Learn about using database versioning and database migrations to handle modifying your database schema after your app has shipped.

  9. Conclusion: Let’s review what you learned about saving data in your app using SQLite, and then discuss what’s next.

Part 4: Room

In the final part, use the new Room library, part of the Android Architecture Components, to save data.

  1. Introduction: Learn about the Architecture Components from Google, including LiveData, ViewModel, and the data peristence library Room that provides a layer above SQLite.

  2. Architecture: Review a new architecture of the DataDrop app that uses Model-View-ViewModel (MVVM) instead of MVP, as preparation for working with LiveData and Room.

  3. Entities and DAOs: Learn about the use of Entities and Data-Access-Objects (DAOs), and see how to set them both up using annotations.

  4. Room Database: See how to create a Room database and how to read from and write data into Room. See also how to use TypeConverters and observe changes to LiveData.

  5. Challenge: Room Database: Practice what you’ve learned about Room by finishing the RoomRepository to handle the delete use cases.

  6. Relationships: See how to setup relationships in a Room database. Also see how to pre-populate Room data using a RoomDatabase.Callback.

  7. Conclusion: In this final episode, we’ll summarize this final part and the whole course, and then see an overview of data persistence topics that were not covered.

The Android Avalanche Bundle

If you like this course, from now until March 30th you can get it along with the rest of our new Android and Kotlin books, courses, and screencasts — at a big discount!

Our new Android Avalanche Bundle includes:

  • Android Apprentice ($54.99 value): Gives you access to our new Android Apprentice book, which teaches you how to build four complete Android apps from scratch. PDF/ePub format.
  • Kotlin Apprentice ($54.99 value): Gives you access to our new Kotlin Apprentice book, which gives you a deep dive into the Kotlin programming language itself. PDF/ePub format.
  • A raywenderlich.com subscription ($19.99 value): Gives you access to all 8 of our new Android video courses, our 2 new Android screencasts, and access to any new courses and screencasts we release in the future.

The bundle price of $99.99 includes the first month of your subscription, which will continue at $19.99/month thereafter. You can cancel at any time and keep the books. This bundle gives you more than 20% off everything in the Android Avalanche!

The Android Avalanche bundle is only available for the next two weeks, so be sure to order your copy while you can.

Already a subscriber? As a subscriber, you already have access to this new course as part of your subscription. You can also enjoy a $20 discount on the bundle that will get you both books added to your collection. It’s our way of thanking you for supporting what we do here at raywenderlich.com.

Where To Go From Here?

If you want to learn Android and Kotlin development — or level up your existing skills – there’s no better way to learn than these new books, courses, and screencasts.

And this is only the beginning! We’re committed to creating more new books, courses, and screencasts on Android development, with the goal of covering Android and Kotlin in the same way that we’ve covered iOS and Swift over the years.

We truly appreciate your support in making this possible. We’re excited about this new chapter at raywenderlich.com. So order your copy of the Android Avalanche Bundle today before the deal is over!

Joe Howard

Joe’s path to software development began in the fields of computational physics and systems engineering. He has been a mobile software developer on iOS and Android since 2009. He now lives in Boston and is Android Team Lead for raywenderlich.com.

raywenderlich.com Weekly

Sign up to receive the latest tutorials from raywenderlich.com each week, and receive a free epic-length tutorial as a bonus!

Advertise with Us!

PragmaConf 2016 Come check out Alt U

Our Books

Our Team

Video Team

... 27 total!

iOS Team

... 81 total!

Android Team

... 39 total!

Unity Team

... 16 total!

Articles Team

... 4 total!

Resident Authors Team

... 30 total!

Podcast Team

... 7 total!

Recruitment Team

... 8 total!