I want to know what is the difference between Adapter and Loader in Android. I have already looked up at the documentation but can't figure out the difference between them. Any help would be appreciated. Thanks!
An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set.
Loaders are special purpose classes that manage loading and reloading updated data asynchronously in the background using AsyncTask. Introduced in Android 3.0, loaders have these characteristics: They are available to every Activity and Fragment. They provide asynchronous loading of data in the background.
An Adapter is responsible for creating and binding data to views. An Adapter isn't an actual view, but instead produces them. An AdapterView is a ViewGroup that gets its child views from an Adapter . E.g. a ListView has a child view for each row in its list.
Android provides several subclasses of Adapter that are useful for retrieving different kinds of data and building views for an AdapterView ( i.e. ListView or GridView). The common adapters are ArrayAdapter,Base Adapter, CursorAdapter, SimpleCursorAdapter,SpinnerAdapter and WrapperListAdapter.
Both provide an abstraction for data access, but the Loader performs the query in the background whereas an Adapter executes in the current (presumably UI) thread.
For example, a straightforward way to access a Content Provider is with a SimpleCursorAdapter. But querying large amounts of data directly from an Activity may cause it to become blocked resulting in an "Application Not Responding" message. Even if it doesn't, users will see an annoying delay in the UI. To avoid these problems, you should initiate a query on a separate thread, wait for it to finish, and then display the results. This is what the CursorLoader will do.
That being said, they are sometimes used in conjunction with one another. In this example data is first loaded with a CursorLoader and then that cursor is updated in an Adapter of an AdapterView for display.
Loader:-
loaders make it easy to asynchronously load data in an activity or fragment
They are available to every Activity and Fragment. They provide asynchronous loading of data.
They monitor the source of their data and deliver new results when the content changes.
They automatically reconnect to the last loader's cursor when being recreated after a configuration change. Thus, they don't need to re-query their data.
Here you find something details about the loader.
Adapter:-
An Adapter object acts as a bridge between an AdapterView
and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set. Here is one video for you. Watch this video then you understand working, advantage of Adapter.
Here is one best tutorial of Adapter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With