Saturday, 4 October 2014

OnLoadFinished() called twice - solution

Recently I was learning cursor adapters and I've noticed strange thing with them. My last project was about parsing colors from colourlovers page and generate  custom views with colors values.

What I noticed was that, the cursorloaders existing in my fragment were called twice instead once.
I checked some posts about it and I found solution. IMHO you must always destroy loadmanagers when you don't want make them run twice. So here is just short snippet how to.

First you call your cursor loader somewhere in onActivityCreated in fragment:

 getLoaderManager().initLoader(0, null, this);   

And then somewhere in onStop in fragment you call: