Android onloadfinished and onloaderreset callback details and examples

Android onloadfinished and onloaderreset callback details and examples

onLoadFinished

This method is called after the previously created loader has completed its loading process. This method is guaranteed to be called before the data applied to the loader is released. In this method, you must delete all use of old data (because it will be deleted soon), but don't release them yourself, because their loader will do these things.

Once the loader knows that the data is no longer used by the application, it will release the data immediately. For example, if the data is a cursor from cursorloader, you should not call the close() of the cursor. If the cursor is placed in a cursoradapter, you should use the swapcursor() method so that the old cursor will not be closed. For example:

onLoaderReset

This method is called when a created loader is reset to invalidate its data. This callback allows you to find out when the data will be released, so you can release the reference to it.

The following implementation calls swapcursor() with null parameter:

example

As an example, a fragment is fully implemented to display the contents of a listview containing query data returned from the contact content provider. It uses a cursorloader to manage the query to the provider.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>