In this Android database tutorial, we’ll be using Active Android for our ORM, or object relational mapping to convert our database data into plain old Java objects (POJOs). This ORM saves us from having to write SQLite code, which is error prone since it’s not checked by the compiler. These are referred to as runtime errors.
In the video below, we show you how to save data between application launches, or in other words, persist that data. We’ll also show you how to retrieve, update and delete the data. We’ll also show you how to link to other objects that are also stored a different database table.
Now, you could do this manually, using Android’s SQLiteOpenHelper class
, or you can abstract that functionality and use what’s called an ORM or Object-relational mapping which is a design pattern for accessing a relational database from our Android code as plain old Java objects. Each ORM is different, so you should choose the best one suited for your particular application and tastes. Even though we’ll be showing you Active Android, many of these concepts apply to other ORMs. Each have their advantages and disadvantages.
Active Android is a very powerful tool as you don’t have to write a single line of SQL code, which is error prone due to the fact that you have to write and construct long SQL commands as strings, where error can’t be detected by the compiler. Instead, you simple mark up your Java object model using Java annotations, extend that Java class with the Model class, and you simply save that model’s data to the database by calling the save method on that object. To update the data, just update that same object, and call save of it again. Active Android will determine if the record is already in the database. If so, it’ll perform an update. If not, it’ll perform an insert operation. To learn more about databases, I have a previous video on databases that you should watch
Android Database Tutorial