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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:21:43+00:00 2026-05-22T18:21:43+00:00

I push a web service call in my activity to a thread (shown below).

  • 0

I push a web service call in my activity to a thread (shown below). The first time I do this in the activity it works fine (gets the text from my edittext and loads the service to get lat/lng data)

But when I click the back button (emulator) and try to fire off this thread a second time it blows up after the .start(); in my click handler. What might I be doing wrong here? thanks

private Thread getLocationByZip = new Thread() {
    public void run() {
        try {
            EditText filterText = (EditText) findViewById(R.id.zipcode);
            Editable zip = filterText.getText();

            LocationLookupService locationLookupService = new LocationLookupService();
            selectedLocation = locationLookupService.getLocationByZip(zip.toString());

            locationHandler.post(launchFindWithLocationInfo);
        } catch (Exception e) {
        }
    }
};

private Runnable launchFindWithLocationInfo = new Runnable() {
    @Override
    public void run() {
        try {
            Intent abc = new Intent(LocationLookup.this, FindWithLocation.class);
            startActivity(abc);
        } catch (Exception e) {

        }
    }
};

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.location);

    locationHandler = new Handler();
    findViewById(R.id.findbyzip).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            getLocationByZip.start();
        }
    });
}

Update

After the great advice I went with an AsyncTask so if anyone finds this going forward the above thread/handler model looks something like the below as an asynctask

private class LocationLookupTask extends AsyncTask<String, Void, Location> {
    private ProgressDialog dialog;

    @Override
    protected void onPreExecute() {
        this.dialog = ProgressDialog.show(LocationLookup.this, "", "Loading...");
    }

    @Override
    protected Location doInBackground(String... zips) {
        Location selectedLocation = null;
        for (String zip : zips) {
            LocationLookupService locationLookupService = new LocationLookupService();
            selectedLocation = locationLookupService.getLocationByZip(zip);
        }
        return selectedLocation;
    }

    @Override
    protected void onPostExecute(Location location) {
        this.dialog.dismiss();

        ((AppDelegate) getApplicationContext()).setSelectedLocation(location);
        Intent abc = new Intent(LocationLookup.this, FindWithLocation.class);
        startActivity(abc);
    }
}

Now to call this in the onclick you would do this

findViewById(R.id.findbyzip).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                EditText filterText = (EditText) findViewById(R.id.zipcode);
                Editable zip = filterText.getText();

                LocationLookupTask task = new LocationLookupTask();
                task.execute(new String[]{zip.toString()});
            }
        });
  • 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-22T18:21:44+00:00Added an answer on May 22, 2026 at 6:21 pm

    You can’t start a thread twice:

    It is never legal to start a thread more than once.

    Taken from Thread.start().

    So, you need to create a new thread and start that one.

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

Sidebar

Related Questions

How can i use Server Push with my WCF web service to communicate with
I have a long running server side process (gets data via a web service
After successfully sent the URI to the web service from the push client, I
we created am Exchange Web Service Push Notifications Listener based on the HTTPListener in
I'm looking to build my first web service and I would like to be
I have some Rails web service, and iOS iPad app. This iPad app need
I want to create a push web application. The service layer is built on
I have a RESTful web service running on Jersey (GlassFish 3.1.1). This one's a
I want to start an application which will use ajax push, however the web
I have a thread push-backing to STL list and another thread pop-fronting from 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.