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

  • Home
  • SEARCH
  • 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 4016848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:47:24+00:00 2026-05-20T09:47:24+00:00

Through the following piece of Android code, I connect to an html page on

  • 0

Through the following piece of Android code, I connect to an html page on the internet and extract few lines. The code executes well most of the time, but it hangs sometimes. I have to press the back button on the mobile to get the ‘Force Close’ dialog. It always runs well on the emulator though (Have a fast connection on the PC).

  1. So, is the code hanging because of a slow EDGE/GPRSconnection on my mobile?
  2. Should I be inserting Socket timeouts?
  3. What other reasons could there be for the code to hang?
  4. How do I prevent the code from hanging? Is there a way to trap the error and return a message to the user before re-trying again?

Please help.

   private String readFile(){
    List<String> scores = new ArrayList<String>();
    String result="";
    String score = "";
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://www.espncricinfo.com/icc_cricket_worldcup2011/engine/current/match/433567.html");
    try{
        HttpResponse response = client.execute(request);
        //txtResult.setText(HttpHelper.request(response));

        try{
            InputStream in = response.getEntity().getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuilder str = new StringBuilder();
            String line = null;
            while((line = reader.readLine()) != null){
                str.append(line + "\n");
            }
            in.close();

            result = str.toString();
            //result = str.toString().substring(1,500);

            Pattern p = Pattern.compile(
                    "<title>(.*)</title>",
                     Pattern.DOTALL
                );
            Matcher matcher = p.matcher(
                     result
                );

            if (matcher.find())
            {
                score = matcher.group(1).toString();
            }

             TextView tv = (TextView)findViewById(R.id.textview);
             tv.setText(score);

            return score;

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(this, "IOException e  = " + e.toString(), Toast.LENGTH_LONG).show();
            Log.d(TAG, "IOException e  = " + e.toString());

            return "IOException e  = " + e.toString();
         }catch(Exception ex){
            result = "Error";
            ex.printStackTrace();
            Toast.makeText(this, "Exception ex  = " + ex.toString(), Toast.LENGTH_LONG).show();
            Log.d(TAG,"Exception ex  = " + ex.toString());
            return "Exception ex  = " + ex.toString();
        }
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(this, "SocketTimeoutException e  = " + e.toString(), Toast.LENGTH_LONG).show();
        Log.d(TAG, "SocketTimeoutException e  = " + e.toString());
        return "SocketTimeoutException e  = " + e.toString();
    }catch(Exception ex){
        Toast.makeText(this, "Exception ex1  = " + ex.toString(), Toast.LENGTH_LONG).show();
          Log.d(TAG, "Exception ex1  = " + ex.toString());
          return  "Exception ex1  = " + ex.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-20T09:47:24+00:00Added an answer on May 20, 2026 at 9:47 am

    Are you running this in the main thread of your application? Longer running processes should execute in a separate thread to avoid slowing down the main thread for the user.

    See the Android Developer guide for example.

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

Sidebar

Related Questions

I have trouble with the following piece of code. When I go through with
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
In the following code I loop through a map and test if an element
I'm using the following code to loop through a directory to print out the
Whilst trawling through some old code I came across something similar to the following:
I use the following code to get through each of values foreach (array('facebook', 'twitter',
I am using the following code to upload a video to Youtube through youtube
I have a paginator that shows the following for page 1 records 1 through
I am trying to go through the following tutorial on asp.net. When I get
While going through university and from following the development of SO, I've heard a

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.