That about covers us on how to load data. Remember, loading from the SD card, network transactions, and longer processing tasks MUST be performed off the main thread, or your application, and users, will suffer. You can, as I’ve shown you in this chapter, use a simple thread, an AsyncTask, or an IntentService to retrieve and process your data. But remember, too, that any action modifying any view or object onscreen must be carried out on the main thread (or Android will throw angry exceptions at you).
Further, keep in mind that these three methods are only a few of many possible background data fetching patterns. Loaders, Workers, and ThreadPools are all other alternatives that might suit your application better than the examples I’ve given.
Follow the simple rules I’ve outlined here, and your app will be fast, it will be responsive to your users, and it will avoid the dreaded App Not Responding notification of doom. Correct use and avoidance of the main thread is critical to producing a successful application.
If you’re more interested in building lists out of complex data from remote sources, the next chapter should give you exactly what you’re looking for. I’ll be showing you how to render a list of Twitter messages to a menu onscreen.
I’ll leave you with a final challenge: Enable Android’s strict mode and move the little file accesses I’ve left in this chapter’s sample code off the main thread. It should be a good way to familiarize yourself with the process before you undertake it on your own.