Simple threads and async tasks work fine when you’re dealing with tasks that take a few seconds. But when you want to manage longer running tasks, such as downloading files from a remote source over the web, you might instead want to use an IntentService class. As with all services, an IntentService class must be registered in the app manifest. When you call it, it runs once and is then automatically destroyed.
- [Instructor] Simple threads and AsyncTasks work fine…when you're dealing with tasks that take a few seconds.…But, when you want to manage longer running tasks…such as, perhaps, downloading files…from a remote source over the web,…you might instead want to use an intent service.…There are a few different kinds of services in Android.…Some of them run on the UI thread…while others run on their own background thread,…but they have certain things in common.…All services run completely disconnected…from the user interface so the code in the service…doesn't have direct access to the view objects in the UI.…
But, this also means that code in the service…doesn't have to concern itself with configuration changes…such as changes in orientation.…And, in order to communicate with the UI…from a service typically you'll use broadcast messages.…Here are some of the most common types of services…that you'll see.…A bound service is a service that started up…from an activity or a fragment…and it's bound to that activity or fragment.…
First, discover how to create and start simple background threads, and how to use handlers to manage a thread's message queue. Then, learn various methods for optimizing the scheduling and performance of background tasks in Android with AsyncTask, intent services, and the JobScheduler API. Plus, explore tools that help you implement multithreading for different tasks in Android: Loader, for asynchronous data loading, and the open-source API Retrofit, for making HTTP requests.
Note: To get the most out of this course, you should be comfortable programming with Java, and should understand the most basic skills that are needed to build Android apps with the Android SDK and Android Studio.
- Creating and running a background thread
- Sending messages to the UI from threads
- Managing multiple background threads
- Managing threads with AsyncTask
- Managing long-running tasks with services
- Scheduling background tasks with JobScheduler
- Using other APIs for concurrent programming