gpt4 book ai didi

java - Android Studio Firebase updateChildren

转载 作者:行者123 更新时间:2023-12-02 10:56:12 25 4
gpt4 key购买 nike

大家好。我在 Android Studio 和 Firebase 中遇到了困难,每当我尝试使用 updateChildren 时,它都会不断替换旧的。我认为它会保留节点内的旧数据,这是代码:

private void getClosestDriver() {
DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference().child("driversAvailable");
GeoFire geoFire = new GeoFire(driverLocation);

geoQuery = geoFire.queryAtLocation(new GeoLocation(pickupLocation.latitude, pickupLocation.longitude), radius);

geoQuery.removeAllListeners();

geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, GeoLocation location) {
if (!driverFound && requestBol) {
driverFound = true;
driverFoundID = key;

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child("Driver").child(driverFoundID).child("passengerRequest");
String passengerID = FirebaseAuth.getInstance().getCurrentUser().getUid();

HashMap map = new HashMap();
map.put("passengerRideID", passengerID);
map.put("destination", destination);
ref.updateChildren(map);

getDriverLocation();
mRequest.setText("Looking for Bus Location....");
}
}

我对 HasMap 的做法正确吗?

最佳答案

将其更改为

String passengerID = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child("Driver").child(driverFoundID).child("passengerRequest").child(passengerID);


HashMap map = new HashMap();
map.put("destination", destination);
ref.updateChildren(map);

关于java - Android Studio Firebase updateChildren,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51717168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com