When i push to create a random generated entry i want to save the randomly generated value as a field inside of itself.
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);
}
Calling push()
generates a new DatabaseReference
with a unique key. You can get that key with:
reference = FirebaseDatabase.getInstance().getReference().child("Guest").push();
String key = reference.getKey();
So you can then write that value into the database where you need it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.