I am publishing file upload progress through NotificationManager, but when updating its progress, the user interface freezes.
I use NotificationCompat.Builder, which is cached in the class field. So posting progress is very simple:
manager.notify(id, uploader. setProgress(MAX_PROGRESS, (int) (progress * 100), false). build() );
Success will be guaranteed to be executed from the main thread (wrapped in a handler decoder).
this.request.setCallback(new UploaderDecorator(this.request.getCallback()));
The publication of progress itself is as follows:
long total = file.length(); long uploaded = 0; int bytesRead = input.read(buffer, 0, bufferSize); while (bytesRead > 0) { output.write(buffer, 0, bufferSize); uploaded += bytesRead; callback.onUploadProgress(activeFile, ((float) uploaded / total)); bytesRead = input.read(buffer, 0, bufferSize); }
So why does it work so slow?
source share