While the info is being consistently downloaded to the server, I want to draw the ProgressDialog, but all the activity sticks before the end of all threads.
private void uploadImageSync() { final ProgressDialog progressDialog; progressDialog = new ProgressDialog(BarcodActivity.this); progressDialog.setMessage("Загрузка фото..."); progressDialog.show(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(ROOT_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); RequestInterface service = retrofit.create(RequestInterface.class); int i=0; while (i++ <= 4) { File f = getOutputMediaFilePath(mCode + "_"+i, true); if(f.exists()){ RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), f); MultipartBody.Part body = MultipartBody.Part.createFormData("file", f.getName(), requestFile); final Call<ResponseBody> resultCall = service.uploadImage(body); Thread t = new Thread(new Runnable() { public void run() { try { ResponseBody r = resultCall.execute().body(); Log.d("MyLog", "загружен"); } catch (IOException e) { e.printStackTrace(); } }}); t.start(); try { t.join(); } catch (InterruptedException e) { e.printStackTrace(); } } } progressDialog.dismiss(); }
Call<ResponseBody>- Bogdan ShulgaresultCall.execute().body();- Bogdan Shulgat.join();You have blocked the current thread (in this case, the UI thread) for a time until each of the threads in the loop dies. Either the loop needs to be moved inside the stream, or as it is correctly suggested: run the following query inonResponse(). In addition, multipart can not send all files at once? - Yura Ivanov