LoaderCallbacks.onLoadFinished() never called with FragmentPager?
<p>I'm using FragmentPagerAdapter to implement a tabbed interface. My 0th fragment creates a loader at creation time, and tries reconnecting to the loader in onActivityCreated(). Here's the class:</p>

<pre><code>public class My0thFragment extends Fragment {
    private boolean ranOnce = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true); 
    }

    @Override
    public void onActivityCreated() {
        if (!ranOnce) {
            // if the first time we're being created, do an initial load of data.
            getLoaderManager().initLoader(500, null, mMyCallback).forceLoad();
            ranOnce = true;
        } else {
            // reconnect?
            getLoaderManager().initLoader(500, null, mMyCallback);

            // sanity check.
            printAllLoaders(getLoaderManager());
        }
    }

    private LoaderManager.LoaderCallbacks&lt;Foo&gt; mMyCallback = new LoaderManager.LoaderCallbacks&lt;Foo&gt;() {
        @Override
        public Loader&lt;Foo&gt; onCreateLoader(int arg0, Bundle arg1) {
            return new FooLoader(getActivity(), arg1);
        }

        @Override
        public void onLoadFinished(Loader&lt;Foo&gt; arg0, Foo arg1) {
            Log.e(tag, "onLoadFinished()!");
        }

        @Override
        public void onLoaderReset(Loader&lt;Foo&gt; arg0) {
            Log.e(tag, "onLoaderReset()!");
        }
    };
}
</code></pre>

<p>And here's the scenario:</p>

<ol>
<li>App starts, the 0th fragment is created in the FragmentPagerAdapter.</li>
<li>The onActivityCreated() method is called, which creates and starts the loader on the first run.</li>
<li>I quickly switch to a different tab, before the loader has completed yet.</li>
<li>I can see through the logs that the loader finishes, but my callback never gets the onLoadFinished() callback. I assume this is because the fragment is in some sort of detached state, depending on how FragmentPagerAdapter works.</li>
<li>Returning back to the 0th tab, I see onActivityCreated() gets called, and the initLoader() method is called again. The callback still doesn't fire.</li>
<li>I can print all the loaders in the loader manager at this point, and see that my loader is still sitting in the loader manager.</li>
</ol>

<p>So I'm stuck here, I must be doing something wrong since the Loader stuff must have been designed for easy use by us developers with fragment lifecycles in mind. Can anyone point out what I'm doing wrong here?</p>

<p>Thank you</p>
