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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:14:25+00:00 2026-05-15T08:14:25+00:00

I have a semi-complicated problem and hoping that someone here will be able to

  • 0

I have a semi-complicated problem and hoping that someone here will be able to help me.

On a click event I create a thread and start a long-running operation based on this method. After the long-running task is completed, it does a callback to another method, which does a post to the handler:

@Override
public void contentSearchModelChanged(Model_ContentSearch csm, ArrayList<Class_Reminder> newRemindersList) {
    remindersList = newRemindersList;
    mHandler.post(mUpdateDisplayRunnable);
}

Which calls a Runnable:

// post this to the Handler when the background thread completes
private final Runnable mUpdateDisplayRunnable = new Runnable() {
  public void run() {
    updateDisplay();
  }
};

Finally, here is what my updateDisplay() method is doing:

private void updateDisplay() {
    if (csModel.getState() != Model_ContentSearch.State.RUNNING) {
        if(remindersList != null && remindersList.size() > 0){
                r_adapter = new ReminderAdapater(Activity_ContentSearch.this, remindersList, thisListView);
                thisListView.setAdapter(r_adapter);
                r_adapter.notifyDataSetChanged();
        }
    }
}

This works beautifully when I do this normally. However, if I change the orientation while the long-running operation is running, it doesn’t work. It does make the callback properly, and the remindersList does have items in it. But when it gets to this line:

r_adapter.notifyDataSetChanged();

Nothing happens. The odd thing is, if I do another submit and have it run the whole process again (without changing orientation), it actually updates the view twice, once for the previous submit and again for the next. So the view updates once with the results of the first submit, then again with the results of the second submit a second later. So the adapater DID get the data, it just isn’t refreshing the view.

I know this has something to do with the orientation change, but I can’t for the life of me figure out why. Can anyone help? Or, can anyone suggest an alternative method of handling threads with orientation changes?

Bara

  • 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-15T08:14:26+00:00Added an answer on May 15, 2026 at 8:14 am

    The problem is that when you change orientations a new activity is spun up from the beginning (onCreate). Your long running process has a handle to the old (no longer visible) activity. You are properly updating the old activity but since it isn’t on screen anymore, you don’t see it.

    This is not an easy problem to fix. There is a library out there that may help you though. It is called DroidFu. Here is a blog post that (much more accurately than I) describes the root cause of what you are seeing and how the DroidFu library combats it: http://brainflush.wordpress.com/2009/11/16/introducing-droid-fu-for-android-betteractivity-betterservice-and-betterasynctask/

    Edit: (Adding code for tracking active activity)

    In your application class add this:

    private Activity _activeActivity;
    public void setActiveActivity(Activity activity) {
        _activeActivity = activity;
    }
    public Activity getActiveActivity() {
        return _activeActivity;
    }
    

    In your Activities, add this:

    @Override
    public void onResume() {
        super.onResume();
        ((MyApplicationClassName)getApplication()).setActiveActivity(this);
    }
    

    Now you can get the active activity by calling MyApplicationClassName.getActiveActivity();

    This is not how DroidFu does it. DroidFu sets the active activity in onCreate but I don’t feel that is very robust.

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

Sidebar

Related Questions

I have a long list of Unicode values that are semi-colon delimited. Here's an
I have a semi-large web application that we run locally and I need to
I am developing a semi-complicated site that is available in several countries at once.
I have an entry.rb model and I'm trying to make a semi-complicated validation. I
I want to have a div that is semi opaque filled with text that
Have a bit of a weird one and hopefully someone can help out. The
We have semi-complicated expressions in the format: 25 + [Variable1] > [Variable2] We need
I have a BackgroundWorker that runs a lengthy and semi-complex task. In this BackgroundWorker,
I am creating a rails app which will help out businesses. These businesses have
We have a semi-weird issue for our site. Consistently, from 1 anonymous* user 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.