In android, getting cursor out of content resolver with query() method can be pain in the ass for pretty much of data. I had experienced it with around 20-30 rows of data from sqlite database. Fortunately, google brought cursor loader for those tasks. It is quite easy to implement as well. First you got to create an empty adapter using "null" as an cursor. Yes, use "null" as your cursor.
Next step is to initiate cursor loader
getLoaderManager().initLoader(0, null, this);
If you are using compatibility pack, you will have to use
getSupportLoaderManager().initLoader(0,null,this);
Here "0" is the key. Loader Manager will try to find loader with id "0". If can't be found, it create Loader with id 0. Next stop is to implements call-backs.
Of course, don't forget implements LoaderManager.LoaderCallbacks
at class declaration. That is and we have a loader which does a nice threading for us.
No comments:
Post a Comment