每次更改Firebase-Database中的数据时如何执行命令?
答案 0 :(得分:1)
You need a ValueEventListener
with the onDataChange
event callback as specified here. With that you access the dataSnapshot
argument and determine the appropriate action to take. Example from the documentation:
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI
Post post = dataSnapshot.getValue(Post.class);
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
// ...
}
};
mPostReference.addValueEventListener(postListener);