title: Return when task is completed
body: <p>I'm facing a problem and I don't know how to solve it.</p>
  
  <p>I'm using firebase firestore to retrieve me an exact Item. This works. 
  The problem comes when I want the task to retun that Item in a custom class.
  Since firebase firestore task is asynchronous it returns null before it's completed.</p>
  
  <p>Here's the code in DataAdapter class:</p>
  
  <pre><code>public Data infoFile(int position){
  
      DocumentReference fileRef = getInfoFile(position); //Method that retrieves the document.
  
      //Array to set later the Data Object that will retrieve
      final Data[] dataArray = {new Data()};
  
      fileRef.get().addOnCompleteListener(new OnCompleteListener&lt;DocumentSnapshot&gt;()
      {
          @Override
          public void onComplete(@NonNull Task&lt;DocumentSnapshot&gt; task)
          {
  
              if(task.isSuccessful()){
                  DocumentSnapshot documentSnapshot = task.getResult();
  
                  if(documentSnapshot.exists()){
  
                      Data data = documentSnapshot.toObject(Data.class); //Get the data
                      dataArray[0] = data; //Set data
                      System.out.println("before put bundle" + dataArray[0].getName()); //This gets the data
                      //Can't return here.
  
                  }
              }
          }
      }).addOnFailureListener(new OnFailureListener()
      {
          @Override
          public void onFailure(@NonNull Exception e)
          {
  
          }
      });
      System.out.println("before put bundle and almost return " + dataArray[0].getName());
  
      //This returns null because task isn't completed yet.  
      return dataArray[0];
  }
  </code></pre>
  
  <p>I've read about creating and interface and then passing the Data to the method and recieve it. But I don't know how to create/understand that. Maybe I'm wrong and that doesn't work.</p>
  
  <p>Question: How can I get to return Data model when task is completed?</p>