让我们列出来自 Google Drive 的文件:
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(
context, DriveScopes.DRIVE);
Drive service = new Drive.Builder(AndroidHttp.newCompatibleTransport(),
new GsonFactory(), credential).build();
service.files().list().execute();
但是,如果没有可用的网络连接,execute() 几乎要花很长时间才能意识到。
从 GoogleAccountCredential 的来源可以看出,它使用 ExponentialBackOffPolicy,默认情况下最大经过时间限制为 15 分钟。
问题 1:有没有办法覆盖此行为并将超时限制设置为较低的值?
问题 2:service.files().list().execute() 在 AsyncTask 中运行。如果她不想等待 15 分钟超时,那么根据用户请求取消它的正确方法是什么?