Using Threads to Download Remote Images with RAD Studio


Scrolling is smooth while loading bitmaps

So what happens if you are loading remote bitmaps into your mobile app and they are slow to load? You’ll likely end up with an application that the user will not be too fond of using. The scrolling of user interface controls will be jerky while your app is waiting for the bitmap data to be transferred over.

To visualize this, download this 1 minute video from the Woll2Woll channel

Video Demonstration of Threading vs Non-Threading

With mobile apps, responsiveness of the user interface (especially with slow internet) is critically important. We can achieve this with Delphi and FireMonkey by creating a background thread for our application that is responsible for loading the bitmaps from the remote server. By using a separate thread, the user responsiveness when touch scrolling will still be smooth. We are going to walk you through how to set this up with a complete working demo. The cool thing about this demo is that a slow server that feeds the bitmap does not degrade the user performance in scrolling through the data.

HousePhotosRemote Application

First download the working app from …

https://github.com/roywoll/RemoteDownloadThread_FMX

Then compile and run the demo for Windows. It will also run in iOS, Android, and OSX. If you can run in iOS, this will be even be better since you can more readily simulate a slower internet connection by disabling wifi and instead force it to use your cellular connection. Then when you compare the performance without using a thread to the performance when you use a thread, you will notice the remarkable difference in responsiveness of your application. The app allows you to toggle between thread or no thread by clicking on the combo at the top right.