Must I use Fragments to get a LoaderManager?
According to some of the documentation I can use a Loader开发者_Go百科 in either an Activity or a Fragment but the Compatibility Package is showing that only a FragmentActivity has the getLoaderManager() method.
Since the old managed cursor has been deprecated we have to use the Cursor Loader. So why should this data management function be tied to a choice of UI widgets ? It makes no sense to me.
thanks P.
Since the old managed cursor has been deprecated we have to use the Cursor Loader.
No, managed cursors still work. Usually, "deprecated" in Android means "we will support this mechanism as long as we can, but we think there are better options".
So why should this data management function be tied to a choice of UI widgets ?
It's not. You do not have to use fragments to inherit from FragmentActivity
. You are also welcome to create your own LoaderManagerCapableActivity
, where you clone the relevant data members and methods from FragmentActivity
(the source code is on your hard drive). However, LoaderManager
has to be associated with an activity, because it is tied into the activity lifecycle, as are the managed cursors. For example, the LoaderManager
instances are passed between activities via onRetainNonConfigurationInstance()
.
Yes, inorder to get loaderManager it must be associated with an a activity however it is possible to use loaders without the need of loaderManger.
1) Implement the AsynTaskLoader.
2) Instantiate the Loader you implemented in your class.
3) Register a listener for your loader so that you will get the callback once the load is complete.
4) Call the startLoading method of the loader.
5) After the load is complete the callback method will be called where you can use the loaded data for any purpose.
精彩评论