Connect data models to a database
If you have a scenario like we have with the Journaler
application to hold the data in the database, and you plan to synchronize it with the remote backend instance, it can be a good idea to first create a persistence layer that will store your data. Keeping data persisted into a local filesystem database prevents data from loss, especially if you have a bigger amount of it!
So, once again, what did we do? We created a persistence mechanism that will store all our data into the SQLite database. Then, in this chapter, we will introduce the backend communication mechanism. Because we don't know if our API calls will fail or whether the backend instance will be available at all, we have the data persisted. If we keep our data in the device memory only, and if the API call for synchronization fails and our application crashes, we can lose this data. Let's say if the API call failed and the application crashed, but we have our data persisted, we can retry the...