[英]How do I save complex data in firebase from android studio?
You can use a Map and set all your data, then just send it to your database 您可以使用地图并设置所有数据,然后将其发送到数据库
Example 例
Map<String, Object> routeUp = new HashMap<>();
routeUp.put("description", "EXAMPLE");
routeUp.put("haultName", "NAME");
routeUp.put("latitude","idontknowwhyyoustoreitwithastring");
//... and so on
mDatabase.child("route").child(routeUp).updateChildren(routeUp).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(mContext, "Success", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(mContext, "Error saving the values " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
you can then merge more than one HashMap
and use putAll
to finally send all the structure in one click 然后,您可以合并多个
HashMap
并使用putAll
键发送所有结构
Example 例
map3 = new HashMap<>();
//...
map3.putAll(map1);
map3.putAll(map2);
Then just push only the Map containing all the structure 然后只推送包含所有结构的地图
Note: be aware that sending so many data like this could cause more than one NPE (NullPointerException) if one or more values are empty, you should handle some kind of exception, 注意:请注意,如果一个或多个值为空,则发送如此多的数据可能会导致多个NPE(NullPointerException),您应该处理某种异常,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.