The AsyncTask architecture is a wrapper around a background thread, but is tightly bound to an activity’s life cycle. You risk losing the task during a configuration change. You can solve that by using a class named AsyncTaskLoader. AsyncTaskLoader does everything AsyncTask does in terms of managing a background thread, but it isn’t as strongly tied to the activity life cycle. It’s still owned by a single activity, but unlike AsyncTask it isn’t interrupted by any configuration changes.
- [Instructor] As I described previously…the AsyncTask Architecture is…a wrap around background thread…but is tightly bound to an activities life cycle.…For any but the quickest tasks,…you risk losing the task during…a configuration change.…You can solve that though…by instead using a class named AsyncTaskLoader.…This class does everything that AsyncTask does…in terms of managing the background thread…but has a key advantage.…It isn't as strongly tied to the activity…life cycle as AsyncTask.…It's still owned by a single activity…when it's implemented the way I'll show you.…
But unlike AsyncTask it won't be interrupted…by a configuration change.…There are two versions of the AsyncTaskLoader…and it's related classes.…One in the main SDK and one in the support repository.…I'll use the support version.…I'm working in a project that starts…over again with the simple blank application…that just has code running features.…Start by declaring a static member class…that extends AsyncTaskLoader and declares…the type of data that will be returned.…
IInstructor David Gassner starts with an overview discussion about available networking strategies, and then dives into how to declare networking permissions, make network requests, handle responses, parse data returned from a web service, and pass user credentials to services that support HTTP basic authentication. He also provides an overview of popular higher-level networking libraries, including OkHttp and Picasso, and offers recommendations for improving performance in network-connected apps. David also covers using static feeds, using dynamic PHP pages hosted on a public server web service, and integrating apps with network data storage.
- Integrating mobile apps
- Communicating with Android
- Preventing app freezes with background threads
- Preparing an app for network communication
- Declaring permissions
- Checking network connectivity
- Retrieving data over the web
- Using traditional APIs
- Using third-party libraries