From the course: Building an Android App with Jetpack Libraries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create a custom type converter

Create a custom type converter - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Create a custom type converter

- [Instructor] My notes table is going to have three columns. The integer and string values are simple values that can be handled by SQLite. That is those types match up with two of SQLite on native column types. But SQLite doesn't have a date type. So I have to convert date values to long integers and back again. So I can store them in my SQLite database. Broom handles this with classes called type converters. You create the converter class and then you register it with your database and Room takes care of everything else. So before I can create my database definition, I need to create a type converter for date values. I'll name this new Kotlin class date converter. The class itself doesn't get any special annotations. Instead you create functions to convert values and then mark those with Room annotation. I'll start with the room annotation type converter. Then I'll create a function named fromTimestamp. This function…

Contents