The abstract class AsyncTask is one of the most popular concurrency tools in Android. It lets you run code in a background thread while still communicating with the user interface. But AsyncTask has a well-known issue: if you declare an AsyncTask object as a member of an Activity, the task can be destroyed along with its parent activity during a configuration change, such as a change in orientation. To prevent this, you can host the asynctask in a fragment object that doesn’t have a user interface. That object can be retained in memory, even during app configuration changes.
- [Voiceover] Mobile applications depend on multithreading…to give the user a sense of good performance.…If you do all of your work on the user interface thread,…the application can freeze up during long-running tasks.…The abstract class "AsyncTask" is one of the most popular…concurrency tools in Android.…It lets you run code in a background thread…while communicating with the user interface.…But AsyncTask has a well known issue.…If you declare an AsyncTask object as a member of…an activity, the task can be destroyed along with its…paired activity during a configuration change,…such as a change in orientation.…
In this project, "AsyncFragment," I've declared…a class that extends AsyncTask.…It has the methods "doInBackground,"…and "onProgressUpdate."…The code "doInBackground" is executed…in the background thread, and "onProgressUpdate"…is executed on the user interface thread…so I can provide information that the user can see.…Whenever I call publishProgress from the…background thread, that data is passed into the…
Author
Updated
8/24/2017Released
3/18/2016Watch these Java tutorials to learn smarter, more efficient methods for Android app development.
- Preparing the development environment
- Packaging and running Android apps
- Optimizing Java code for Android
- Implementing event handler interfaces
- Defining custom callback methods
- Working with the Android SDK's Java packages
- Storing data
- Reading text files
- Parsing JSON and XML data
- Managing device sensors
- Playing audio
Skill Level Beginner
Duration
Views
Related Courses
-
Learning Java 8
with Peggy Fisher3h 9m Beginner -
Java Essential Training for Students
with Peggy Fisher3h 6m Intermediate -
Java 8 Essential Training
with David Gassner6h 7m Beginner
-
Introduction
-
Welcome48s
-
What you need to know2m 18s
-
Using the exercise files3m 38s
-
What's new in this update?1m 19s
-
-
1. Getting Started
-
2. Android's Implementation of Java
-
3. Common Java Design Patterns in Android
-
Manage async tasks in fragments11m 19s
-
4. The Android SDK's Java Packages
-
Manage local databases10m 57s
-
Read text files from assets9m 20s
-
Parse JSON formatted data8m 29s
-
Parse XML formatted data9m 52s
-
5. Android-Specific Java Packages
-
Manage device sensors8m 4s
-
Use text to speech6m 39s
-
Play audio files8m 39s
-
6. Java 8 Syntax for Android
-
Explore more Java syntax1m 24s
-
Conclusion
-
Next steps1m 13s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Manage async tasks in fragments