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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:56+00:00 2026-06-17T12:33:56+00:00

I must use Thread in an Android project. Sometimes, it works corectly, however sometimes

  • 0

I must use Thread in an Android project. Sometimes, it works corectly, however sometimes does not; it does not start (does not call SendToServer() method)or it starts but return to another function suddenly (return updated; line)before the thread does not finish.

Note: affected value is bigger than 0, it gives condition and it goes to if statement.

Here is the my code sample;

public static Boolean MyUpdateFunction(MyObject myobject){

Boolean updated=false;
//Code for updating local database


int affected= SqliteDb.update(....);

if(affected>0)
{
    //Send updated data to server
    //For this I must use Thread(I can't use AsyncThread)
    updated=true;
    SendToServer();

}


return updated;
}

public static void SendToServer()

{
    try{
        ;
        Thread th=new Thread(new Runnable() {

        public void run() {
            try {

                //Create data and send it to server
                //.......
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    th.start();
    th.join();




}
catch(SQLException e)
{
    Toast.makeText(myContext,"ERROR: "+e.getMessage(), Toast.LENGTH_LONG).show();
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
}
  • 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-17T12:33:56+00:00Added an answer on June 17, 2026 at 12:33 pm

    Instead of using threads and your variables (updated and affected), you can use AsyncTasks: see: http://developer.android.com/reference/android/os/AsyncTask.html

    With AsyncTask, you have some methods which are doing exactly what you want:

    • onPreExecute
    • doInBackground
    • onPostExecute

    So, what you can do is to check your condition in onPreExecute, then do your SendToServer in the doInBackground and onPostExecute do what you need.

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

Sidebar

Related Questions

I am programming a c project which must use the pow function defined in
I have a ~2MB file that my Google AppEngine server must use (not serve)
I have an ArrayList of Routine objects and I must use this method to
I have a PhoneGap/Cordova project that means I must use a combination of JQuery
I need to design a thread-safe logger. My logger must have a Log() method
Some say that one must use UIApplication in main thread, but I don't see
i creating for stopwatch with start,stop i use following code it started but not
I have a Dispatcher that I must use to update my bitmap, however the
I read many posts saying multithreaded applications must use a separate session per thread.
I am not clear about thread confinement. In swing all the gui components must

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.