I'm trying to figure out how to use Firebase properly, so I made this simple code, saving a "game" object with code and password. I also made it show the game's key on the screen. running the code, it works and shows what looks like a key on the screen, but I can't find any of the data anywhere on my Firebase Console. Here's the code:
public class testthing extends AppCompatActivity implements View.OnClickListener {
EditText pass;
TextView showkey;
EditText code;
Button create;
String codestr;
String passstr;
FirebaseDatabase firebaseDatabase;
DatabaseReference gameRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testthing);
pass = findViewById(R.id.pass);
code = findViewById(R.id.code);
create = findViewById(R.id.create);
showkey = findViewById(R.id.showthingy);
firebaseDatabase = FirebaseDatabase.getInstance();
create.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if(view==create){
codestr=code.getText().toString();
passstr=pass.getText().toString();
Game g = new Game(codestr,passstr,"");
gameRef = firebaseDatabase.getReference("gameRooms").push();
g.key = gameRef.getKey();
gameRef.setValue(g);
showkey.setText(g.key);
}
}
}
with the "game" class being:
@IgnoreExtraProperties
public class Game {
public String key;
public String code;
public String password;
public Game(){
}
public Game(String code, String password,String key){
this.code = code;
this.password = password;
this.key = key;
}
}