问题
Overview: Using child layout within my MainActivity (to accept and update values into firebase database)
Whenever firebase gets updated, my child layout gets called too (which I am usually launching on tap of button to accept and update data into firebase database)
I've cross-checked, if I don't call updateData() then firebase never gets hit and everything works so smoothly (I mean never launch my child layout unnecessarily)
So, my concern is, how can I control on a launch of child layout, which gets launched whenever firebase gets updated
Calling acceptData() method to accept data from user
buttonAcceptUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
acceptData();
}
});
Here is the code, I'm using inside acceptData()
private void acceptData() {
View view = getLayoutInflater().inflate(R.layout.layout_data, null);
acceptDialog = new Dialog(MainActivity.this);
acceptDialog.show();
......
btnSaveData = view.findViewById(R.id.buttonSave);
btnSaveData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
acceptDialog.dismiss();
updateData(); // if not calling this method then acceptData layout not getting called
}
});
}
Calling updateData() method to update data into Firebase
private void updateData() {
Map updateHashMap = new HashMap<>();
updateHashMap.put("address_1", add1);
updateHashMap.put("address_2", add2);
mUsersRef.updateChildren(updateHashMap);
}
来源:https://stackoverflow.com/questions/62037592/android-firebase-gets-updated-child-layout-gets-called-too-weird-issue