i have an android project in progress where the user will have the chance to play some games like tik tak toe, Rock–paper–scissors etc. For the database I use Room persistence so i want to create 12 instances one for each game. Each game has name, targetSkill etc etcGame tic_tac_toe = new Game("tic tac toe", "attention"....) . I would like to create these 12 instances when the user install the app and then store them in the database. I don't know how to do this. Where i should place the code for the instances in order to run once?? Here is the model for the game (Game class)
@Entity(tableName = "games")
public class Game {
@PrimaryKey(autoGenerate = true)
@NonNull
private int id;
@ColumnInfo(name = "name")
@NonNull
private String name;
@ColumnInfo(name = "targetSkill")
@NonNull
private String targetSkill;
@ColumnInfo(name = "description")
@NonNull
private String description;
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
private byte[] image;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@NonNull
public String getName() {
return name;
}
public void setName(@NonNull String name) {
this.name = name;
}
@NonNull
public String getTargetSkill() {
return targetSkill;
}
public void setTargetSkill(@NonNull String targetSkill) {
this.targetSkill = targetSkill;
}
@NonNull
public String getDescription() {
return description;
}
public void setDescription(@NonNull String description) {
this.description = description;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
public Game(@NonNull String name, @NonNull String targetSkill, @NonNull String description) {
this.name = name;
this.targetSkill = targetSkill;
this.description = description;
}
@Ignore
public Game(@NonNull String name, @NonNull String targetSkill, @NonNull String description, byte[] image) {
this.name = name;
this.targetSkill = targetSkill;
this.description = description;
this.image = image;
}
}
i have also one more java Class called Game Helper where i create the inastances for the games
String stoneDesc = "the screen displays 2 images (rock, paped, scissor) and the user has to pick " + "the appropriate image. It depends on Lose or Win Mode";
Game Rock =new Game("Rock","skill",stoneDesc,logoImage);