Skip to content

Instantly share code, notes, and snippets.

@hassanabidpk
Created June 11, 2017 14:32
Show Gist options
  • Save hassanabidpk/3698638b6660e2906078c216e79b8b98 to your computer and use it in GitHub Desktop.
Save hassanabidpk/3698638b6660e2906078c216e79b8b98 to your computer and use it in GitHub Desktop.
/* Create new object at /user-runs/$userid/$runid and at
* /runs/$runid simultaneously
*/
String key = mDatabase.child("runs").push().getKey();
MyRun run = new MyRun(userId, mCity, mDate, mHost, mTitle, mWeather, mWebsite, mLat,
mLng, mLocation, mMapUrl, mTemperature, "strava", activity, photo_url);
Map<String, Object> postValues = run.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/runs/" + key, postValues);
childUpdates.put("/user-runs/" + userId + "/" + key, postValues);
mDatabase.updateChildren(childUpdates).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// sucess
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment