Android Programming: The Big Nerd Ranch Guide, Third Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano
For the More Curious: Alternatives to AsyncTask
If you use an AsyncTask to load data, you are responsible for managing its lifecycle during configuration changes, such as rotation, and stashing its data somewhere that lives through those changes. Often, this is simplified by using setRetainInstance(true) on a Fragment and storing the data there, but there are still situations where you have to intervene – and code you have to write to ensure that everything happens correctly. Such situations include the user pressing the Back button while the AsyncTask is running, or the fragment that launched the AsyncTask getting destroyed during execution by the OS due to a low-memory situation.
Using a Loader is an alternative solution that takes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access