Sign in Go Pro

Storing Data in Android with Room

Inserting Entities with the @Insert Annotation

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Up next



In this lesson, we'll describe the @Insert annotation. We'll see how it can be used to provide a convenient way to insert entities into a Room database.

We'll show how to define a function on the DAO which can be used to insert Tasks into the database. We'll use the @Insert annotation which will allow us to avoid writing any SQL at all.

Summary of Content:

  • Restriction around accessing the database from the UI thread
  • @Insert annotation []
  • Defining an insert function in the DAO
  • Returning ID of newly inserted entity
  • Returning IDs of newly inserted entities when bulk added
  • Room's handling of transactions when using @Insert





There are no comments on this lesson, start the conversation below ...


Lessons in Storing Data in Android with Room