The following Java code retrieves clothes data from a Firebase database. However, the Log.d(tag, "moved")
and Log.d(tag, "signed in")
lines don't print any messages and the main Activity is frozen.
public ArrayList<Clothe> getAllClothes() throws InterruptedException {
synchronized (ClotheFirebaseHelper.this) {
mAuth.signInWithEmailAndPassword("#########@gmail.com","**************").addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
ClotheFirebaseHelper.this.notifyAll();
Log.d("tag","signed in");
}
});
ClotheFirebaseHelper.this.wait();
}
Log.d("tag","moved");
String uid = Objects.requireNonNull(mAuth.getCurrentUser()).getUid();
Task<DataSnapshot> task = reference.child(uid).get();
synchronized (ClotheFirebaseHelper.this) {
task.onSuccessTask(new SuccessContinuation<DataSnapshot, Object>() {
@NonNull
@Override
public Task<Object> then(DataSnapshot dataSnapshot) throws Exception {
ClotheFirebaseHelper.this.notifyAll();
return null;
}
});
ClotheFirebaseHelper.this.wait();
}
Log.d("tag","ready?");
Log.d("tag",task.getResult().toString());
return null;
}