This is part of the "Android and Kotlin for Beginners" learning path. View Path

Saving Data on Android

Mar 27 2018 · Beginner · Video Course · 2 hrs, 7 mins

Learn various ways to persist data in your app: SharedPreferences, saving data to files, using SQLite, and using the Room library from Google.

Version

  • Kotlin 1.2, Android 4.4+, Studio 3.0.1

SharedPreferences

Introduction

2:37 Free

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

1

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

2

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

3

Learn how to save data into SharedPreferences, and how to read the data back in.

4

Practice what you've learned so far to save data into SharedPreferences and then read the data back in.

5

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

6

Practice some more with the Repository pattern by deleting data from the SharedPreferences repository.

7

Conclusion

0:53

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.

8

Saving to Files

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

9

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.

10

See how to read files from internal storage using the Java SDK FileInputStream and BufferedReader classes.

11

Practice what you've learned about saving to internal storage by safeguarding your app against read and write errors.

12

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.

13

Update the FileRepository to delete files, using some of the helper functions you've already developed.

14

Finish the use of the FileRepository for saving app data by practicing what you've learned to delete files.

15

Conclusion

0:52

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.

16

SQLite

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

17

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.

18

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

19

Practice what you've learned so far about SQLite and ContentValues to write data into the SQLite database.

20

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

21

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

22

Finish the use of the SQLiteRepository for saving app data by practicing what you've learned to delete files.

23

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

24

Conclusion

0:56

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

25

Room

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

26

Architecture

14:22

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.

27

Entities and DAOs

3:17 Free

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

28

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.

29

Practice what you've learned about Room by finishing the RoomRepository to handle the delete use cases.

30

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

31

Conclusion

1:37

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.

32

Contributors

Comments