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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:48:54+00:00 2026-05-27T21:48:54+00:00

My Android app employs a particularly big computation which keeps crashing the system because

  • 0

My Android app employs a particularly big computation which keeps crashing the system because it is on the UI thread in the Activity.
I have little confidence in multithreading and so I want to get some tips on how to do it correctly.
This is what I have

class ActivtyName extends Activity{
boolean threadcomplete = false;

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//stuff

Runnable newthread = new Runnable(){

            @Override
            public void run() {
                doBigComputation();
                threadcomplete=true;
            }

        };

        newthread.run();

        boolean b = true;
        while(b){
            if(threadcomplete){
                b=false;
                startTheApp();
            }
        }

}
}

Now, I am pretty sure what I have done is not “correct”. (It seems to work though. The sistem doesn’t crash). Basically, I’m not sure how the UI thread can be told that newthread has finished the computation without this boolean, threadcomplete. Is there a “correct” way to do this?

  • 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-27T21:48:54+00:00Added an answer on May 27, 2026 at 9:48 pm

    Just to expand a bit on Marek Sebera’s comment, here’s the framework on how you would accomplish that in an AsyncTask.

    private class BigComputationTask extends AsyncTask<Void, Void, Void> {
    
      @Override
      protected void onPreExecute() {
        // Runs on UI thread
        Log.d(TAG, "About to start...");
      }
    
      @Override
      protected Void doInBackground(Void... params) {
        // Runs on the background thread
        doBigComputation();
      }
    
      @Override
      protected void onPostExecute(Void res) {
        // Runs on the UI thread
        Log.d(TAG, "Big computation finished");
        startTheApp();
      }
    
    }
    

    And to call it:

    BigComputationTask t = new BigComputationTask();
    t.execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Android app has a ContactsList activity in which I simply display a list
My android app is simple : a single activity contains a webview which shows
We have an Android app and a Web Service. We want to download part
I have an Android app with a ListActivity in the main view. The list
I've got an Android app which has a periodic background Service. I want this
My android-app gets List in the one activity, but activity,that contains the LisView for
My Android app should do the following: The MainActivity launches another thread at the
My Android app has a main WebView (HTML loaded from a local resource) which
Every activity within my android app is generated using HTML. When one of the
My android app works on landscape mode. I have a listview that contains some

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.