Android loader-Overview

Source: Internet
Author: User

The loader function is introduced in android3.0, which makes it easy to load data asynchronously in activity or fragment. The loader has the following features:

1. The loader is valid for every activity and fagment;

2. The loader provides the ability to load asynchronous data;

3. The loader monitors data resources and sends new results when the content changes;

4. When the configuration is changed and re-built, the loader automatically reconnects to the final loader cursor. Therefore, you do not need to re-query the data.

There are multiple types of interfaces available for application loaders. The following table provides an overview:

Class/interface

Description

Loadermanager

An abstract class associated with activity and fragment to manage one or more loader instances. This is useful for managing long-time operations combined with activity or fragment lifecycles. The most common is the cursorloader. However, to load other types of data, you can write your own applications for your applications.

Each activity or fragment has only one loadermanager, but one loadermanager can have multiple loaders.

Loadermanager. loadercallbacks

The callback interface used for customer interaction with loadermanager. For example, you can use the oncreateloader () callback method to create a new loader.

Loader

An abstract class that executes asynchronous data loading. This is the base class of the loader. Generally, cursorloader is used, but its own subclass can also be implemented. The loader should monitor the data source during activation and send new results when the content changes.

Asynctaskloader

An abstract loader that provides an asynctask object to complete the work.

Cursorloader

Asynctaskloader subclass, which queries the contentresolver object and returns a cursor object. This class uses the standard cursor query method to implement the loader protocol. Based on the asynctaskloader object, the background thread is used to execute the cursor query, so that the interface of the application will not be deadlocked. Using this loader is the best way to asynchronously load data from the contentprovider object, rather than executing managed queries through fragment or the APIs of the activity.

The classes and interfaces in the above table are necessary components for implementing the Application Loader. Each loader you create does not need all of the above content. However, to initialize a loader, you always need to reference A loadermanager object and implement a loader class like the cursorloader class. The following sections show you how to use these classes and interfaces in an application.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.