Answer the question
In order to leave comments, you need to log in
How to block an Activity while downloading files?
Hello! I have an activity that has a button to download a book from the server. When I click it, I want to display the progressbar for the entire time the files are being loaded. All in all, a typical task. But several files are loaded, using the . And I can't figure out how to block the actions in the activity and display the progressbar while ALL files are downloading. The library loads files in a separate thread.
Maybe I can upload files directly in the UI thread, without a library? Then the user will definitely not do anything until the files are loaded. But this is a bad idea, IMHO, if the connection is not very good, it will fail.
Tell me, in which direction to "dig", maybe there are some examples?
Here is my method to load files and write to memory:
private void downloadFilesBook(String[] urlsFiles) {
mFetch = Fetch.newInstance(this);
String folderB = "bookfiles_" + bookId;
String fileNameForWrite = "book_" + bookId + ".json";
File bookfolder = new File(String.valueOf(getExternalFilesDir(folderB)));
ArrayList<String> pagesFiles = new ArrayList<>();
for (int i = 0; i < urlsFiles.length; i++) {
String url = urlsFiles[i];
String path = String.valueOf(bookfolder);
String fileName = Uri.parse(url).getLastPathSegment();
Log.d("my2", fileName);
Request request = new Request(url, path, fileName);
String pageFilePath = path + "/" + fileName;
Log.d("my2", pageFilePath);
pagesFiles.add(pageFilePath);
downloadId = mFetch.enqueue(request);
}
BookFiles bookFiles = new BookFiles();
bookFiles.setBookID(bookId);
ArrayList<String> pagesPath = getPagesArray(pagesFiles);
ArrayList<String> soundsPath = getSoundsArray(pagesFiles);
bookFiles.setPagesPath(pagesPath);
bookFiles.setSoundsPath(soundsPath);
Gson gson11 = new Gson();
String filesJson = gson11.toJson(bookFiles);
MyJSON.saveData(getApplicationContext(), filesJson, fileNameForWrite);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question