Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:08:22+00:00 2026-05-31T18:08:22+00:00

I have an activity which uses two Loaders. Each of them returns different type

  • 0

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 LoaderCallbacks<D> into an Activity. I guess I could just implement LoaderCallbacks<Object> 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).

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

private static class geocoderLoaderCallbacks implements LoaderCallbacks<List<Address>>{

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

    @Override
    public void onLoadFinished(Loader<List<Address>> loader, List<Address> data) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onLoaderReset(Loader<List<Address>> loader) {
        // TODO Auto-generated method stub

    }


}

And then using lm.initLoader(0, null, geocoderLoaderCallbacks).

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 lm.initLoader(0, null, geocoderLoaderCallbacks(this))?

There is a similar question here LoaderManager with multiple loaders: how to get the right cursorloader but it doesn’t explain how to manage two loaders with different data types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:08:23+00:00Added an answer on May 31, 2026 at 6:08 pm

    It is always ok to move code away from a potentially giant class and it’s much cleaner to do it with different classes then with one that can handle everything. You might even want to make them real external classes instead of inner classes if you feel that your Activity has too much code inside. LoaderCallbacks is an interface so you can and mostly should implement it in it’s own class.

    Passing the Context in the constructor is fine as long as you don’t keep static or otherwise cached references to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have silverlight 2.0 application and which uses WCF service to get data and
I have a question regarding calling a method from one activity in a different
I have an activity in Android which uses a ListView. When I click on
I have an Activity which starts an AsyncTask. This AsyncTask uses AutoCompleteTextView.showDropDown() in onPostExecute.
I have an Android app which includes an activity called Help This uses a
I have an Activity which uses a Fragment . I simply want to pass
I have an activity which shows some List entries. When I click on a
I have created an activity which sends a number of notifications to status bar.
I have a couple of tables which are used to log user activity for
Say if I have a locationManager(LM) object in activity A, which is my main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.