All I have to do is get the return value from the insert as a long. I got that but it isn't working, I am getting back 0 from the returned value. I am using a DAO
, Repository and ViewModel
as stated in the Google CodeLabs. I have followed this post Rowid after Insert in Room.
Player Class
@Entity(tableName = "player_table")
public class Player {
@PrimaryKey(autoGenerate = true)
private long id;
@NonNull
@ColumnInfo(name = "username")
private String username;
}
DAO
@Insert
long insert(Player player);
Repository
public long insert(Player player) {
new insertAsyncTask(mPlayerDao).execute(player);
rowId = player.getId();
return rowId;
}
ViewModel
public long insert(Player player){
rowId = mRepository.insert(player);
return rowId;
}
Activity
String playerString = editTextUsername.getText().toString();
Player player = new Player(playerString);
long rowId = mDreamViewModel.insert(player);