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 6580571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:02:45+00:00 2026-05-25T16:02:45+00:00

When using a custom AsyncTaskLoader to download data from a web service, if I

  • 0

When using a custom AsyncTaskLoader to download data from a web service, if I press the HOME button in the middle of the loading process and then enter the app again, the onLoadFinished() method is not called. My fragment is calling setRetainInstance(true) in onActivityCreated() and it also calls getLoaderManager.initLoader(0, null, this) in the same method (as is recommended).

While testing, I see that when coming back to the fragment onActivityCreated() is not called so this may be why onLoadFinished() is not called. But where else to put the initLoader() method? I’ve read in several places that it should not be called in onResume().

So, any ideas? I have a lot of loaders in various screens in my app and I need to solve this issue in an elegant way.

  • 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-25T16:02:45+00:00Added an answer on May 25, 2026 at 4:02 pm

    After looking at Issue 14944 (http://code.google.com/p/android/issues/detail?id=14944), I solved the issue by overriding onStartLoading() in my custom AsyncTaskLoader and call forceLoad().

    An even better solution is to create a custom parent AsyncTaskLoader that looks like this (taken from a suggestion by alexvem from the link above):

    public abstract class AsyncLoader<D> extends AsyncTaskLoader<D> {
    
        private D data;
    
        public AsyncLoader(Context context) {
            super(context);
        }
    
        @Override
        public void deliverResult(D data) {
            if (isReset()) {
                // An async query came in while the loader is stopped
                return;
            }
    
            this.data = data;
    
            super.deliverResult(data);
        }
    
    
        @Override
        protected void onStartLoading() {
            if (data != null) {
                deliverResult(data);
            }
    
            if (takeContentChanged() || data == null) {
                forceLoad();
            }
        }
    
        @Override
        protected void onStopLoading() {
             // Attempt to cancel the current load task if possible.
            cancelLoad();
        }
    
        @Override
        protected void onReset() {
            super.onReset();
    
            // Ensure the loader is stopped
            onStopLoading();
    
            data = null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am using Custom Google search in my web page Code: <div id=cse style=width: 100%;>Loading</div>
I've been trying to switch from using PerlSetEnv to using custom configuration directives .
I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to
Background : I am currently using custom controls within my C# project (basic controls
I am creating a installer in .NET and using custom actions for controlling installation.
I'm using a custom-built inhouse application that generates a standard set of reports on
I am using some custom controls one of which is a tooltip controller that
We are using a custom FTP application (which encrypts the files) for secure transfers.
I am using a custom item renderer in a combobox to display a custom
I'm using a custom tintColor on my UINavigationController 's navigation bar, and because the

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.