An IntentService is designed to run tasks in the background, and is well-suited to longer-running tasks. Unlike AsyncTask, an IntentService is completely detached from the user interface. It isn’t contained within an activity, and can’t call the activity’s methods. But it can communicate back to the app’s visual layer using broadcast messages.
- [Narrator] An intent service is designed to run tasks…in the background and is well suited to…longer running tasks.…Unlike AsyncTask or AsyncTaskLoader, an intent service…is completely detached from the user interface.…It runs in its own thread and doesn't have access…to the main thread.…It isn't contained within an activity, and it can't…call the activity's methods, but it can communicate…back to the app's visual tier using broadcast messages,…and because it's using broadcast messages, it can send…information to any component in the application,…not just a single activity.…
Start by creating a class that extends intent service.…In this project, I'm going to create a new sub package,…and I'll name it Services.…And in that sub package I'll create a new Java class,…and I'll name it MyService,…and I'll set the superclass to IntentService.…This class is a member of the package Android.app.…I'll get rid of that comment, and I'll fix up a couple…of error conditions.…First of all, I'll implement a required abstract method…
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