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 put in multiple logs and they proved useless. I started putting in break points and checking the variable of id of player or also the one I made rowId and still all of the come back 0 in many places.
Player Class
DAO
Repository
ViewModel
Activity
Player Class
Java:
@Entity(tableName = "player_table")
public class Player {
@PrimaryKey(autoGenerate = true)
private long id;
@NonNull
@ColumnInfo(name = "username")
private String username;
}
DAO
Java:
@Insert
long insert(Player player);
Java:
public long insert(Player player) {
new insertAsyncTask(mPlayerDao).execute(player);
rowId = player.getId();
return rowId;
}
Java:
public long insert(Player player){
rowId = mRepository.insert(player);
return rowId;
}
Java:
String playerString = editTextUsername.getText().toString();
Player player = new Player(playerString);
long rowId = mDreamViewModel.insert(player);