Android Room - Get the id of new inserted row with auto-generate
Based on the documentation here (below the code snippet)
A method annotated with the @Insert
annotation can return:
long
for single insert operationlong[]
orLong[]
orList<Long>
for multiple insert operationsvoid
if you don't care about the inserted id(s)
@Insert
function can return void
, long
, long[]
or List<Long>
. Please try this.
@Insert(onConflict = OnConflictStrategy.REPLACE)
long insert(User user);
// Insert multiple items
@Insert(onConflict = OnConflictStrategy.REPLACE)
long[] insert(User... user);