This talk is about how to easily persist data in Android using the Room library from the architectural components from Google. Gave the talk at the Android Nigeria meetup.
provided by Google. Google describes Room as providing “an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.”
AUTOINCREMENT NOT NULL, firstName TEXT, lastName TEXT) @PrimaryKey(autoGenerate = true) @NonNull public final String id; public final String firstName; public final String lastName; Auto-Generated Primary Keys
{ public final int accountNumber; public final String accountType; AccountThingy(int accountNumber, String accountType) { this.accountNumber = accountNumber; this.accountType = accountType; } } CREATE TABLE IF NOT EXISTS AccountThingy (accountNumber INTEGER, accountType String NOT NULL, PRIMARY KEY(accountNumber, accountType))
public final String id; public final String regNo; public final String name; public Student(String id, String regNo, String name) { this.id = id; this.regNo = regNo; this.name = name } } CREATE INDEX index_Student_regNo ON Student (regNo)
public class Student { @PrimaryKey public final String id; public final String regNo; public final String name; @Ignore private String something; public Student(String id, String regNo, String name) { this.id = id; this.regNo = regNo; this.name = name } }
single entity (e.g. findById() returning a single Person) • A collection of entity (e.g selectAll() return a List of Person entities) • A Cursor • A Flowable or Publisher from RxJava2 • A LiveData Object