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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:16:44+00:00 2026-06-16T17:16:44+00:00

I have AsyncTask doing background work and populating ListView in its onProgressUpdate and calling

  • 0

I have AsyncTask doing background work and populating ListView in its onProgressUpdate and calling notifyDataSetChanged() on adapter. Problem is that when orientation changes, AsyncTask stops. How can I make AsyncTask keep doing its work and populating ListView with results no matter what? I cant use android:configChanges="keyboardHidden|orientation" because my layout is different in landscape mode. Also I tried using Service class, but I was unable to access my UI components. What is the most simple way to achieve what I am after for?

  • 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-06-16T17:16:45+00:00Added an answer on June 16, 2026 at 5:16 pm

    You could use a callback method to update your listView. You need to implement it in your AsyncTask and call if directly from your doInBackground or onProgressUpdate:

    private updateListViewListener mListener;
    
    
    public interface updateListViewListener{
        void updateListView(List<String> rowsData);     
    }
    
    public void setUpdateListViewListener(updateListViewListener listener) {
        mListener = listener;
    }
    

    And then in doInBackGround (or onPogressUpdate):

    @Override
        protected Object doInBackground(Object... arg0) {
        //Code that downloads data or executes time consumming code that calls the following interface when the data of a row is ready
         mListener.updateListView(listOfStrings); 
    }
    

    Then in your activity you can save a reference of your AsyncTask in another class:

    RandomClass.saveAsyncTask(yourAsynctask);
    

    This way you can get a reference to your AsyncTask even if the activity is recreated adding something like this on your oncreateView():

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
            YourAsyncTask task = RandomClass.getAsyncTask();
            if(task != null){
                newAsyncTask =  task;
                newAsyncTask .setUpdateListViewListener(this); // you set again the listener
            }
        }
    

    And finally you can add this to the updateListView method you will be overriding in your activity:

    @Override
        public void updateListView(List<String> newDataFromAT) {
            adapter.setData(newDataFromAT);
                // You need to do this since you can't change anything in the UI from doInBakcground
            getActivity().runOnUiThread(new Runnable() {
                    public void run() {
              adapter.notifyDataSetChanged();
                    }
                });
        }
    

    This is just some code that I think will work for you since You didn’t posted any code but you get the idea that when you rotate your device the AsyncTask can’t update something that has been destroyed like a listView so it’s better to keep the reference to the asyncTask.

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

Sidebar

Related Questions

I have an AsyncTask and on the background I want to start Service that
I have a nested AsyncTask. This simple example is proof that they work: http://pastebin.com/0R9Cfxx1
I have a code that just don't work! The AsyncTask needs to return a
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
My goal is to have an AsyncTask that can execute multiple times (one task
I have an asynctask that parses an xml file from the net. I'm storing
I have two AsyncTask that are not working. There must be something in common
I have MainActivity which does some Work before it Executes an AsyncTask called Datensammlung.
I have Asynctask in my activity. The problem is when I setText in onPostExecute()
I have a very strange problem. I have an AsyncTask which appears to block

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.