Detailed explanation of the use of LoaderManager (4) --- Example: AppListLoader

Example: AppListLoader

This article will be my fourth and final article in the series. Please let me know in the comments if they are useful. The links to the previous articles are as follows:

1: The world before Loaders
2 : Understanding LoaderManager
3: Implementing Loaders
4: Example: AppListLoader In

response to popular demand, I have written a sample application to demonstrate how to properly implement a custom Loader. The application name is: AppListLoader, it is a demo application that can query and list all installed applications on your Android device. The application has been modified and rebuilt (without bugs) with the LoaderCustom.java example provided in the API Demos. The app uses AppListLoader (a subclass of AsyncTaskLoader) to query data, and LoaderManager to manage the contents of Loader in the Activity/Fragment declaration cycle.

AppListLoader registers two BroadcastReceivers to listen for system-wide broadcasts that affect the underlying data source. This is the meaning of the sentence, which is very troublesome to translate). Newly installed, updated, and removed applications are monitored by InstalledAppObserver. Locale changes are monitored by SystemLocaleObserver. For example, when the user changes the language from English to Spanish, the SystemLocaleObserver will detect it and notify the AppListLoader to re-query the data, so that the program can display the Spanish name of each application (if each application provides the corresponding Spanish language name). Click the "Change language" button and watch the Loader respond seamlessly to this event (cool, isn't it!!).

When events related to Loader/LoaderManager occur, Log information will be displayed in Logcat. So when analyzing Logcat, remember to make sure the program is running. Hope it gives you a better understanding of how Loader and LoaderManager work together, and how the Activity/Fragment life cycle affects them. You can use the app name "com.adp.loadercustom" to filter for better results.

The app can be downloaded from Google Play by clicking the link below:

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327059678&siteId=291194637