LoaderCallbacks as a static inner class (to handle multiple Loaders with different data types returned)
<p>I have an activity which uses two Loaders. Each of them returns different type of data. To get data from a single Loader one just implements <code>LoaderCallbacks&lt;D&gt;</code> into an Activity. I guess I could just implement <code>LoaderCallbacks&lt;Object&gt;</code> and check the type of the object and then decide which of the two LoaderCallbacks it is, but it seems like a hack to me (mostly because of the lack of type safety here).</p>

<p>So I thought about making the LoaderCallbacks object a static inner class, something like this:</p>

<pre><code>private static class geocoderLoaderCallbacks implements LoaderCallbacks&lt;List&lt;Address&gt;&gt;{

    @Override
    public Loader&lt;List&lt;Address&gt;&gt; onCreateLoader(int arg0, Bundle arg1) {
        GeocoderTask loader = new GeocoderTask(context, "");
        return loader;
    }

    @Override
    public void onLoadFinished(Loader&lt;List&lt;Address&gt;&gt; loader, List&lt;Address&gt; data) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onLoaderReset(Loader&lt;List&lt;Address&gt;&gt; loader) {
        // TODO Auto-generated method stub

    }


}
</code></pre>

<p>And then using <code>lm.initLoader(0, null, geocoderLoaderCallbacks)</code>.</p>

<p>Two question arise: is it ok to do, or should I rather stick to implementing LoaderCallbacks into Activity? And how do I safely pass the context into the onCreateLoader? Should I just make a constructor in geocoderLoaderCallbacks and pass the context there like this <code>lm.initLoader(0, null, geocoderLoaderCallbacks(this))</code>?</p>

<p>There is a similar question here <a href="http://stackoverflow.com/questions/7957418/loadermanager-with-multiple-loaders-how-to-get-the-right-cursorloader">LoaderManager with multiple loaders: how to get the right cursorloader</a> but it doesn't explain how to manage two loaders with different data types.</p>
