Architecture components - persistence and offline (Google I/O '17)

Android Developers · 39K views · 2017 · 39:31

Open on YouTube

Software architecture & designDatabases & storageSoftware (other)talkdated

Why Stack Overflow recommends it

Stack Overflow users link it as the official introduction to Room, especially when answering questions about entity relationships and embedded objects.

Recommended by 3 people across 3 different months, 2016 to 2018.

What it is

A Google I/O 2017 session from the Android team, presented by Yigit Boyar, introducing the Room persistence library as part of the Architecture Components. It covers how to build a database-backed Android app with less boilerplate while keeping compile-time checks on SQL, plus approaches for offline persistence.

What people said

Recommends CommonsWare · 2017-05 · Stack Overflow · on “Android Room: How to model relationships?”

"Did I understand it correctly?" -- yes, that is how I am interpreting Room. They cover this point in the Google I|O 2017 presentation on Room [this video] , towards the end.

Recommends Amir Uval · 2017-07 · Stack Overflow · on “Create/Update SQLite database from json file”

If your JSON tree structure will not change often, you can make a PoJo for it with a tool such as jsonschema2pojo [LINK] . And convert instances using Gson. You can store this PoJo using Google's new library: Room Persistence Library [LINK] . It can save the PoJo for you (You'll need to annotate it with @Entity ) in sqlite database, and it can update you on changes in the database. For more details you can watch the Google I/O presentations [this video] .

Recommends hara · 2018-01 · Stack Overflow · on “Room database with one-to-one relation”

@AhmedHegazy, `@Relation` seems to me not the proper solution to the one-to-one relation problem. The documentation says `The type of the field annotated with Relation must be a List or Set.` so it doesn't fit very well with a one-to-one relation. Looking at Yigit Boyar introduction to Room [this video] , it seems to me that the best solution would be to create a third POJO class.

Cites Matthew Weber · 2016-06 · Stack Overflow · on “What is the correct way to initialize data in a lookup table using DBFlow?”

The answer below is correct, but I believe that this Answer and Question will soon be "deprecated" along with most third-part ORMs. Google's new Room Persistence Library [LINK] ( Yigit's Talk [this video] ) will be preferred in most cases. Although DBFlow will certainly carry on (Thank You Andrew [LINK] ) in many projects, here is a good place to re-direct people to the newest "best practice" because this particular question was/is geared for those new to DBFlow. The correct way to initialize the database (akin to the SQLiteOpenHelper's onCreate(db) callback is to create a Migration object [LINK] that extends BaseMigration [LINK] with the version=0 , then add the following to the onCreate() in th

Cites Sonu Sanjeev · 2018-01 · Stack Overflow · on “How to query nested Embeded objects using Room Persistance Library in android?”

Yes "nested embedded objects" are permitted inside ROOM. You can write a User class which has an embedded Address class as which contains a embedded Location class. Each time when an embedded object is added, room flattens out the table. In your case room generates a table called "User" with the following columns: id, firstName, addr_street, addr_state, addr_city, addr_post_code, addr_home_lat, addr_home_lng, addr_office_lat, addr_office_lng So your query should be like : @Query("SELECT * FROM User WHERE " + "addr_home_lat BETWEEN :lat1 AND :lat2" + " AND addr_home_lng BETWEEN :lng1 AND :lng2") List<User> findInRange(long lat1, long lat2, long lng1, long lng2); Notice that "lat" has been fla