Optimize UI responsiveness with AsyncTask
Hello developers of VLC-android,
I'm doing research related to Android apps' responsiveness. I found there are some cases in VLC-android that database is queried, or bitmap is generated in UI thread. Do these long operations in UI thread affect the responsiveness of the app? An optimization could be extracting these operations into AsyncTask.
For example, in AudioBrowserListAdapter.java, line 207 "AudioUtil.getCover()" decodes a bitmap from a stream, which is a relative long computation. Is it better to put it into a AsyncTask, so the UI thread won't be blocked on decoding? I attach a sample patch here.
Also, in VideoPlayerActivity.java, "onClick" method at line 1286 and 1333 updates database via "MediaDatabase". Thus, I tried to move it into AsyncTask, too. Note that after putting it into AsyncTask, there will be data races on "mLocation", because "mLocation" is written in "load()" method (line 1674) but read at line 1286 and 1333. So I add synchronization for the access to "mLocation".
Similarly, I refactor some other files. I totally refactor 13 places in 8 files in the patch that is attached here.
There should be some other places that can be improved. I can't report all of them at one time. However, what do you think about this kind of improvements? My thought is we can improve the responsiveness if we try to avoid the access to IO/Database, generating bitmap in UI thread.
Thanks, Yu