In firebase, getInstance() method is used to retrieve the instance thenreference the location you want to write.setValue() method is used to set the value to the particular reference. FirebaseDatabase database = FirebaseDatabase.getInstance();DatabaseReference myRef = database.getReference("message");myRef.setValue("Hello, World!");
2.Read:-
The FirebaseDatabase give us a lot of methods and listener, to verify when all database was updated, when a specific child was updated and etc. DataSnapshot : A DataSnapshot instance contains all the data from a firebase database for a particular node. Any time when you want to read Database data, you receive the data as a datasnapshot. DataSnapshot will be returned in the listeners methods that you attach to the DatabaseReference: addValueEventListener(ValueEventListener),{onDataChange(),onCancelled()} addChildEventListener(ChildEventListener), onCancelled(DatabaseError error)// This method will be triggered in the event that this listener either failed at the server, or is removed as a result of the security and Firebase rules. onChildAdded(DataSnapshot snapshot, String previousChildName) // triggered when a new child is added to the location to which this listener was added. onChildChanged(DataSnapshot snapshot, String previousChildName) // triggered when the data at a child location has changed. onChildMoved(DataSnapshot snapshot, String previousChildName)// triggered when a child location's priority changes. onChildRemoved(DataSnapshot snapshot)// triggered when a child is removed from the location to which this listener was addedaddListenerForSingleValueEvent(ValueEventListener).
This comment has been removed by the author.
ReplyDelete