Skip to content

Commit

Permalink
change when the database listeners are attached and remove them in on…
Browse files Browse the repository at this point in the history
…Destroy
  • Loading branch information
MANZARACI committed Mar 7, 2023
1 parent 5bf1c05 commit eacb150
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {

mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
currentUser = mAuth.getCurrentUser();

queue = Volley.newRequestQueue(this);

Expand Down Expand Up @@ -126,6 +127,12 @@ public void onCancelled(@NonNull DatabaseError error) {

}
};

mDetectedFacesRef = mDatabase.child("users").child(currentUser.getUid()).child("detectedFaces");
mDetectedFacesRef.addValueEventListener(detectedFacesListener);

mLocationRequestRef = mDatabase.child("users").child(currentUser.getUid()).child("locationRequest");
mLocationRequestRef.addValueEventListener(locationRequestListener);
}

private void sendLocation() {
Expand Down Expand Up @@ -242,20 +249,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
}

@Override
protected void onStart() {
super.onStart();
currentUser = mAuth.getCurrentUser();
if (currentUser != null) {
if (mDetectedFacesRef == null) {
mDetectedFacesRef = mDatabase.child("users").child(currentUser.getUid()).child("detectedFaces");
mDetectedFacesRef.addValueEventListener(detectedFacesListener);
}

if (mLocationRequestRef == null) {
mLocationRequestRef = mDatabase.child("users").child(currentUser.getUid()).child("locationRequest");
mLocationRequestRef.addValueEventListener(locationRequestListener);
}

}
protected void onDestroy() {
super.onDestroy();
mDetectedFacesRef.removeEventListener(detectedFacesListener);
mLocationRequestRef.removeEventListener(locationRequestListener);
}
}

0 comments on commit eacb150

Please sign in to comment.