How do I set a variable inside of an onComplete method?

currently I am trying to pass a value to String variables inside of an onComplete() method. But, when I tried to use it outside of the method, it passes nothing.

Here's my onComplete code:

docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
            if(task.isSuccessful()){
                DocumentSnapshot document = task.getResult();
                if(document.exists()){

                    Log.d(TAG,"User full name: " + document.getString("FullName"));
                    Log.d(TAG, "User email: " + document.getString("Email"));
                    donorFullName = document.getString("FullName");
                    donorEmail = document.getString("Email");
                    Log.d(TAG, "donorFullName set: " + donorFullName);
                    Log.d(TAG, "donorEmail set: " + donorEmail);

                }
            }
        }
    });

And here's me trying to use it outside of onComplete:

    BookingInformation bookingInformation = new BookingInformation();
    Log.d(TAG, "donorFullName bookingInformation: " + donorFullName);
    Log.d(TAG, "donorEmail bookingInformation: " + donorEmail);
    bookingInformation.setDonorName(donorFullName);
    bookingInformation.setDonorEmail(donorEmail);

Here's my logcat:

enter image description here



from Recent Questions - Stack Overflow https://ift.tt/3aVqlvp
https://ift.tt/37Xwaq5

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation