My code retrieves boolean values from a Firebase realtime database. However, those values automatically delete themselves for no apparent reason. I cannot see why this is happening and am going insane.
The code should work like so: create view, download booleans if they exist, done.
This is what seems to be happening: create view, download booleans if they exist, erase them, done.
Here is my code:
public class ACdayFragment extends Fragment {
//TAG
private static final String TAG = "ACdayFragment";
//Context
private Context context;
//Days for Booleans
Boolean Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday;
//Firebase Stuff
FirebaseMethods firebaseMethods;
DatabaseReference userDatabase;
DatabaseReference availDatabase;
FirebaseAuth mAuth;
//Strings
String key = mAuth.getInstance().getUid();
//TreeMap
TreeMap<Integer, Boolean> dayMap = new TreeMap<>();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_ac, container, false);
    mAuth = FirebaseAuth.getInstance();
    key = FirebaseAuth.getInstance().getUid();
    userDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(key);
    availDatabase = userDatabase.child("Days");
    //This method should populate my dayMap treemap
    getData();
    //But when I retrieve it here, it appears empty
    Log.e(TAG, "getData0: "+ dayMap);
    return view;
}
private void getData() {
    FirebaseUser user = mAuth.getCurrentUser();
    if (user != null) {
        availDatabase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (getActivity() == null) {
                    return;
                }
                if (dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0) {
                    Map<String, Boolean> map = (Map<String, Boolean>) dataSnapshot.getValue();
                    if (map.get("sunday")!= null) {
                        dayMap.put(0, true);
                    }
                    if (map.get("monday")!= null) {
                        dayMap.put(1, true);
                    }
                    if (map.get("tuesday")!= null) {
                        dayMap.put(2, true);
                    }if (map.get("wednesday")!= null) {
                        dayMap.put(3, true);
                    }if (map.get("thursday")!= null) {
                        dayMap.put(4, true);
                    }if (map.get("friday")!= null) {
                        dayMap.put(5, true);
                    }if (map.get("saturday")!= null) {
                        dayMap.put(6, true);
                    }
                    //This log does show me a populated dayMap
                    Log.e(TAG, "getData1: "+ dayMap );
                }
            }
            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
            }
        });
    }
    Log.d(TAG, "getData2: " + dayMap );
}
@Override
public void onStart() {
    super.onStart();
}
@Override
public void onStop() {
    super.onStop();
}
}
 
     
    