1. Darksymphony's Avatar
    In my android app I have an option to backup the database to Google Drive. For that I am using DriveServiceHelper class, but I just noticed, in Android 11 the Task.call is deprecated.

    This is a part of the DriveServiceHelper class:

    Code:
          public Task<FileList> queryFiles() {
        return Tasks.call(mExecutor, () ->
                mDriveService.files().list().setSpaces("drive").execute());
    }
    And from my BackupActivity then I call queryFiles from backup method:

    Code:
     public void backup(View v) {
            driveServiceHelper.queryFiles()
                    .addOnSuccessListener(fileList -> {
                      // another code
                    })
                    .addOnFailureListener(e -> showMsgSnack(getString(R.string.uploaderror)));
    I did not find any solution how to deal with this to avoid complete rework of that class.

    What I tried:

    I tried to replace with runnable, also callable, but it doesn't work as Task is expected to be returned, not Filelist.

    also I tried to use TaskCompletionSource:

    Code:
     public Task<FileList> queryFiles(int delay) throws IOException {
            TaskCompletionSource<FileList> taskCompletionSource = new TaskCompletionSource<>();
        
            FileList result = mDriveService.files().list().setSpaces("drive").execute();
            new Handler().postDelayed(() -> taskCompletionSource.setResult(result), delay);
        
            return taskCompletionSource.getTask();
    
    }
    But when I call queryFiles(1000) from my main class, it gives me error:

    java.lang.IllegalStateException: Calling this from your main thread can lead to deadlock.

    I'll appreciate any help.
    11-16-2021 05:25 PM

Similar Threads

  1. Pixel 6 call volume too loud
    By Android Central Question in forum Google Pixel 6 & Pixel 6 Pro
    Replies: 20
    Last Post: 11-29-2021, 06:00 AM
  2. Google speech to text. Not deleting the text once you send the message
    By philipdepalo in forum Google Pixel 6 & Pixel 6 Pro
    Replies: 2
    Last Post: 11-21-2021, 09:04 PM
  3. Replies: 3
    Last Post: 11-16-2021, 10:59 PM
  4. Why is my phone calling 911 when it connects to my vehicle Bluetooth.
    By Android Central Question in forum Ask a Question
    Replies: 2
    Last Post: 11-16-2021, 07:48 PM
  5. Pixel 6 call volume too loud
    By Android Central Question in forum Ask a Question
    Replies: 0
    Last Post: 11-15-2021, 07:12 PM
LINK TO POST COPIED TO CLIPBOARD