AsynctaskLoader reset state

This may sound like a silly question, but I cannot wrap my head in the AsynctaskLoader state.

I've read the documentation several times as well as other tutorials on the internet. However, I still cannot figure out when Asynctask is in Reset state

Take a look at this bit of code pulled from the official documentation. http://developer.android.com/reference/android/content/AsyncTaskLoader.html

@Override public void deliverResult(List<AppEntry> apps) {
    if (isReset()) {
        // An async query came in while the loader is stopped.  We
        // don't need the result.
        if (apps != null) {
            onReleaseResources(apps);
        }
    }

      

This method is called, then the loader is executed with its work and needs to send data back to the UI thread. My question is, why are we asking if Loader is Reset ?. What does Reset mean to him? The class says

/**
 * Return whether this load has been reset.  That is, either the loader
 * has not yet been started for the first time, or its {@link #reset()}
 * has been called.
 */ 

      

You might think that if the bootloader was not started the first time, the STOPPED statement states why it was rebooted ?.

I guess I don't quite understand how Loader reacts to the activity lifecycle, but the documentation doesn't say anything about it.

+3


source to share


2 answers


"However, I still cannot figure out when the Asynctask is in the Reset state.

I believe you meant "... when the LOADER is at rest"

Typically LoaerManager can be used to manage the lifecycle of loaders.

When the user calls LoaderManager # destroyLoader (), LoadManager removes this loader from the cache. The loader can also be destroyed by calling LoaderManager # restartLoader () or by passing the Activity / Fragment it destroys the phase. If such a loader has previously delivered data to its client (usually a Fragment or Activity), then the LoaderManager will call onLoaderReset () and instruct the loader to reset. This gives the client the ability to remove any data references and the loader free up any data related resources. Remember that the loader is the owner of the data, not the client.

"My question is, why are we asking if the Loader is Reset?"

deliverResult is called in the context of the UI thread, but is triggered when the background thread completes that does the actual download. The loading state can be changed to reset () before the background thread finishes. The isReset () check is performed to avoid notifying the client of new data in this race condition when the bootloader is in the Reset state.



"What does this mean to him as a Reset?"

The bootloader in the Reset state must stop all its operations, as it may be destroyed soon after. In particular, it should release any resources occupied by the previously loaded data, stop loading new data, and stop monitoring changes in the underscore data source.

"You would think that if the bootloader was not started the first time, it would be in the STOPPED statement, why did you reboot?"

A stopped state indicates that the bootloader was previously in a running state. In a stopped state, the loader can have previously loaded data and watch for changes in the underscore data source. In the off state, the bootloader can return to the initial state or to the Reset state. If it is reloaded, it can use its previously loaded data if there were no changes to the data source when it was stopped.

When the bootloader is created but before it is started, it is considered in the Reset state. This works well because there is no data loaded in this state yet, and also the bootloader should not be performing any operations as stated above.

+2


source


I think this will help you



I think this will help you. This map shows the life cycle and life cycle of a forklift truck.

+3


source







All Articles