title: google drive api for android delay retrieve created file
body: <p>What I'm trying to do here - is to create a file in my drive via Google Drive Api and retrieve/restore when the file is ready</p>
  
  <p>I use this function bellow to create file :</p>
  
  <pre><code>    private void sendToDrive(File file,String nameFile){       
       getDriveResourceClient()
              .createContents()
              .continueWithTask(task -&gt; {
                  DriveContents contents = task.getResult();
                  OutputStream outputStream = contents.getOutputStream();
                  FileInputStream fis = new FileInputStream(file);
                  byte[] buffer = new byte[1024];
                  int length;
                  while ((length = fis.read(buffer)) &gt; 0) {
                      outputStream.write(buffer, 0, length);
                  }
  
                  MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                          .setTitle(nameFile)
                          .setStarred(true)
                          .build();
  
                  return getDriveResourceClient().createFile(AppFolder, changeSet, contents);
              }).addOnSuccessListener(new OnSuccessListener&lt;DriveFile&gt;() {
                  @Override
                  public void onSuccess(DriveFile driveFile) {
  
                     Log.e("sendFile","onSuccess");
                  }
              }).addOnCompleteListener(new OnCompleteListener&lt;DriveFile&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;DriveFile&gt; task) {
                      Log.e("sendFile", "OnComplete");
                  }
              });
  
  
  }
  </code></pre>
  
  <p>When I call this function for a file I can see both log OnComplete and OnSuccess.</p>
  
  <p>But just after that if I list the files in the folder - I cannot find the file ( especially if it is a big file )</p>
  
  <p>I use this method to get the list of all files in a the drive folder in question:</p>
  
  <pre><code>protected void getAllFileFromDrive(){
      DriveApi.MetadataBufferResult metadataBufferResult = AppFolder.listChildren(getDriveClient().asGoogleApiClient()).await();
  
      if (!metadataBufferResult.getStatus().isSuccess()) {
          metadataBufferResult.release();
      }else
      {
  
          MetadataBuffer metadataBuffer = metadataBufferResult.getMetadataBuffer();
          if (metadataBuffer.getCount() == 0) {
              metadataBuffer.release();
          }else{
  
              for (int i = 0 ; i &lt; metadataBuffer.getCount(); i++)
              {
                  Metadata item = metadataBuffer.get(i);
                 if (item==null || item.getOriginalFilename()== null)
                      continue;
                  Log.e("File",item.getOriginalFilename());
              }
              metadataBuffer.release();
              metadataBufferResult.release();
          }
  
      }
  
  }
  </code></pre>
  
  <p>But I don't find the file in the log, so I need wait some time so I can see it.
  I tried to call syncRequest, and nothing changed, I need to wait like 1 minutes or more ( if the file is more big ).
  I can understand that drive is doing some stuff with my file in the background , but I'll like to know when he is done or wait until he done all the process.</p>
  
  <p>All my code is for Android using Drive API with <code>implementation 'com.google.android.gms:play-services-drive:17.0.0'
  </code> in my gradle ( and it deprecated ).</p>
  
  <p>Thanks.</p>