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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:15:19+00:00 2026-06-13T05:15:19+00:00

I suspect I’m running into some issues borne out of threading in my simple

  • 0

I suspect I’m running into some issues borne out of threading in my simple Android app.

I have a Activity which does the following:

  1. runs a dialog on main thread
  2. spins a background thread and hits a PHP script for retreiving data using DefaultHttpClient and close this connection. This successfully returns a URL to a picture on the internet
  3. open HttpUrlConnection called conn and try conn.connect
  4. app freezes at this point with no error

Not sure what code to put here, I could paste it all but that would be too much so let me know if any more info is needed:

/**
 * Background Async Task to Load all Question by making HTTP Request
 */
class LoadAllImages extends AsyncTask<String, String, String> {
  /**
   * Before starting background thread Show Progress Dialog
   * */
  @Override
  protected void onPreExecute() {
    super.onPreExecute();
    // dialog init'd here
  }

  @Override
  protected String doInBackground(String... args) {
    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    // getting JSON string from URL
    JSONObject json = jParser.makeHttpRequest(url_question_details, "GET", params);



    // Check your log cat for JSON response
    Log.d("All Questions: ", json.toString());

    try {

        // images found
        // Getting Array of questions
        images = json.getJSONArray(TAG_IMAGES);

        // looping through All questions
        for (int i = 0; i < images.length(); i++) {
          JSONObject c = images.getJSONObject(i);

          // Storing each json item in variable
          String id = c.getString(TAG_IMAGEID);
          String location = c.getString(TAG_IMAGELOCATION);

          URL myFileUrl = null;
          try {
            myFileUrl = new URL(location);
          } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          try {
            HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
            conn.setDoInput(true);
            conn.connect(); // freezes here
            int length = conn.getContentLength();
            int[] bitmapData = new int[length];
            byte[] bitmapData2 = new byte[length];
            InputStream is = conn.getInputStream();
          } catch (IOException 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-13T05:15:20+00:00Added an answer on June 13, 2026 at 5:15 am

    Remove these 2 lines:

    conn.setDoInput(true);
    conn.connect(); // freezes here
    

    When you do this:

    HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
    int length = conn.getContentLength();
    

    You are already connected. Calling conn.getContentLength() causes HttpURLConnection to make the connection, sends the request and fetches the response. You don’t need to explicitly connect. You also don’t need to call setDoInput(true) since that is the default setting.

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

Sidebar

Related Questions

I suspect that the ContentControl which have a property of ContentTemplate is either a
I'm using ClearCase 7.1 I suspect we have some evil twins. I'm looking for
I suspect I have performed an incorrect amendment (B') of last commit (B), which
I suspect this is impossible, but thought I'd ask. Say I have a class
One day I suspect I'll have to learn hadoop and transfer all this data
I suspect I have corrupt mergeinfo but I'm not sure. Does anyone know how
I suspect that RegSetValueEx is thread safe, but would like some confirmation from the
I have what I suspect is a malfunctioning wireless access point, the symptom of
I have what I suspect to be a logic problem with an algorithm I
I suspect we have a major memory leak in our ActiveMQ connection bridge -

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.