当我推送创建一个随机生成的条目时,我想将随机生成的值保存为自身内部的一个字段。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
manager = (LocationManager) getSystemService(LOCATION_SERVICE);
reference = FirebaseDatabase.getInstance().getReference().child("Guest").push();
getLocationUpdates();
readChanges();
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
答案 0 :(得分:0)
调用 push()
会生成一个具有唯一键的新 DatabaseReference
。您可以通过以下方式获取该密钥:
reference = FirebaseDatabase.getInstance().getReference().child("Guest").push();
String key = reference.getKey();
这样您就可以将该值写入需要它的数据库中。