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

  • SEARCH
  • Home
  • 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 836403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:58:32+00:00 2026-05-15T04:58:32+00:00

When it comes to threads and orientation changes, it seems the normal thing to

  • 0

When it comes to threads and orientation changes, it seems the normal thing to do is something like this:

public class Bwent extends Activity {
    private static Bwent instance;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        instance = this;
    }

    //...

That way, if you’re making a network request with a thread, and someone changes the orientation of the phone, the thread will know to use the new Activity.

However, is it possible that the thread could finish during the time Android is destroying the old Activity and creating a new one?

Is there a moment in the process where the thread still might be pointing to the wrong Activity, or a partially destroyed activity?

It seems like there shouldn’t be, but even using a Handler created in the main thread, I’m having intermittent issues with a thread trying to update an object that no longer exists. It’s rare, but it does happen.

  • 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-15T04:58:32+00:00Added an answer on May 15, 2026 at 4:58 am

    When it comes to threads and
    orientation changes, it seems the
    normal thing to do is something like
    this:

    It is a thing to do. I am not certain whether or not it is the “normal” thing to do. I am dubious that it is the best thing to do.

    However, is it possible that the
    thread could finish during the time
    Android is destroying the old Activity
    and creating a new one?

    Yes. There is nothing in your code preventing it.

    Is there a moment in the process where
    the thread still might be pointing to
    the wrong Activity, or a partially
    destroyed activity?

    Yes. There is nothing in your code preventing it.

    Instead, try the pattern that I illustrate here. Use an AsyncTask, implemented as a static inner class or a public class. Have it be the one that knows about the Activity. Have it only use the Activity in doPostExecute() (or possibly onPublishProgress()). From the way AsyncTask and Handler work, our understanding is that the AsyncTask will always have an Activity in those on-the-main-thread methods.

    Some of this stuff was discussed recently.

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

Sidebar

Ask A Question

Stats

  • Questions 538k
  • Answers 538k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Before and after is what aspect oriented programming is for.… May 17, 2026 at 2:02 am
  • Editorial Team
    Editorial Team added an answer A couple options. use a separate form for the postcode… May 17, 2026 at 2:02 am
  • Editorial Team
    Editorial Team added an answer Typically, most content management systems will store images the actual… May 17, 2026 at 2:02 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a simple method which is called from multiple threads; @Override public Bitmap
i saw comment like this one place i have seen this problem is if
This simple program starts with 15 threads - according to the count. Sometimes during
How do threads that rely on one another communicate in Java? For example, I
I dont understand why Threads have to sleep if there is no event in
I understand threads in theory, but I have no idea how to implement them
I have an app that starts 10 threads. Each thread does it's work and
A tester sent this crash file: Not sure what an EXC_CRASH is. UPDATE: I
I've got some threads doing heavy work while my main thread handles the UI
I noticed a few strange behaviors in a Windows Forms scenario which involves threads

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.