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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:28:54+00:00 2026-05-25T19:28:54+00:00

When the user launches my Android App, I fire up 2 threads to do

  • 0

When the user launches my Android App, I fire up 2 threads to do some processing in the background. thread_1 does some calculations on the client, and thread_2 fetches some data from the server. That all works fine. None of the threads modify the UI. I have two follow up questions.

new Thread(new Runnable(){
    @Override
    public void run(){
        MyClass.someStaticVariable = doSomeCalculations();
    }
}).start();
  1. What is the best practice to retrieve the data from the run() method of a thread? I currently have a static variable, and I assign the relavent calculated data/ fetched data to it. Or is it recommended to use the Handler class to get data out of threads? I imagined one only uses the handler if they wish to update the UI.

    while(true)
    {
        if (!thread1.isAlive() && !thread2.isAlive())  
        {
            startActivity(intent)
        }
    }
    
  2. I need to wait until both threads are finished before I can pass the data from both threads via an Intent. How can I achieve that? I can do it using the code shown above, but that just seems wrong.

  • 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-25T19:28:55+00:00Added an answer on May 25, 2026 at 7:28 pm

    You could use a Future. It will block on get until the data is available: http://developer.android.com/reference/java/util/concurrent/Future.html

    An alternative is to pass a CountDownLatch into the threads and call countDown() when exiting the run method: http://developer.android.com/reference/java/util/concurrent/CountDownLatch.html

    final CountDownLatch latch = new CountDownLatch(2);
    new Thread(new Runnable(){
      @Override
      public void run(){
        // Do something
        latch.countDown()
      }
    }).start();
    new Thread(new Runnable(){
      @Override
      public void run(){
        // Do something
        latch.countDown()
      }
    }).start();
    
    latch.await()
    startActivity(intent)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an Android app where in the user can set the daily reminder,
I need to make an android App that when the user navigates to my
when my android app - Activity B - is moved to the background (by
It seems like a standard requirement: next time the user launches the application, open
OK I am trying to make it so that when a user launches my
I'd like to be able to compile an Android app on my desktop, upload
I have a problem with an app i'm currently making for Android phones. I
Okay, so, I am making a Tumblr client for Android, I've been trying and
I have am wrighting an android app and as a part of the app
What is the appropriate way to implement a location-based Android app that periodically sends

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.