按顺序运行android IntentService / Service

时间:2017-02-21 18:03:28

标签: android

我尝试使用Amazon S3上传类发送文件,但它只发送所有Async,我需要发送大量的文件,但要避免所有网络数据被阻止,因为这样,我想找一种方式发送顺序文件:

我在看什么:

ExecutorService es = Executors.newSingleThreadExecutor();
 es.submit(new Runnable() {
                @Override
                public void run() {
                  transferUtility = S3.getTransferUtility(getApplicationContext());
                    TransferObserver observer = transferUtility.upload(S3.BUCKET_NAME, file.getName(), file);
                    observer.setTransferListener(new TransferListener() {
                        @Override
                        public void onStateChanged(int id, TransferState state) {
                            if (TransferState.COMPLETED.equals(state)) {

                            }
                            Log.d(SERVICE_NAME, "[onStateChanged] ID: " + id + " --- State: " + state);
                        }

                        @Override
                        public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
                            Log.d(SERVICE_NAME, "[onProgressChanged] ID: " + id + " --- bytesCurrent: " + bytesCurrent + " --- BytesTotal: " + bytesTotal);
                        }

                        @Override
                        public void onError(int id, Exception ex) {
                            ex.printStackTrace();
                            Log.d(SERVICE_NAME, "[onError] ID: " + id);
                        }
                    });
                }
            });
        }

但它仍然并行运行

有没有办法在没有创建一个CallBack / Interface来接收下载完成后启动它而不是启动下一个?

0 个答案:

没有答案