Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
It is possible to stop a thread that is connecting to URL with httpConnection.connect()?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
saex  
View profile  
 More options Oct 5 2012, 7:39 pm
From: saex <elpablos...@gmail.com>
Date: Fri, 5 Oct 2012 16:39:55 -0700 (PDT)
Local: Fri, Oct 5 2012 7:39 pm
Subject: It is possible to stop a thread that is connecting to URL with httpConnection.connect()?

i have a thread that is connecting to a url to obtaining some data.

Sometimes the method httpConnection.connect(); taked too munch time to get
the response, and i want to limit the loading dialog of this connection
thread to 5 seg.

I tryed adding timeouts into the code, *but it doesn't work*!!

            URL formattedUrl = new URL(url);
            URLConnection connection = formattedUrl.openConnection();
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);
            HttpURLConnection httpConnection = (HttpURLConnection) connection;
            httpConnection.setAllowUserInteraction(false);
            httpConnection.setInstanceFollowRedirects(true);
            httpConnection.setRequestMethod("GET");
            httpConnection.setConnectTimeout(5000);
            httpConnection.setReadTimeout(5000);
            httpConnection.connect();

So, i must stop the connect method and the thread when 5000 seconds have
passed or when the used has pressed the back key on the phone.

How can this be achieved? i can't find info about doing this work in
android with a url connection thread.

thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ed Harned  
View profile  
 More options Oct 6 2012, 10:08 am
From: Ed Harned <edhar...@gmail.com>
Date: Sat, 6 Oct 2012 07:08:56 -0700 (PDT)
Local: Sat, Oct 6 2012 10:08 am
Subject: Re: It is possible to stop a thread that is connecting to URL with httpConnection.connect()?

Do your connection in a separate thread or AsyncTask. You can time the
thread and ignore it if it takes too long. Now you'll be getting into
thread control which really is a whole other subject.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Streets Of Boston  
View profile  
 More options Oct 9 2012, 10:21 am
From: Streets Of Boston <flyingdutc...@gmail.com>
Date: Tue, 9 Oct 2012 07:21:58 -0700 (PDT)
Local: Tues, Oct 9 2012 10:21 am
Subject: Re: It is possible to stop a thread that is connecting to URL with httpConnection.connect()?

Run the code you posted above in a back-ground thread (either as a plain
thread or an AsyncTask's 'doInBackground(...)' implementation).

After 5 seconds or on user input, call either the back-ground thread's
'interrupt()' method (if you are using a plain Thread) or 'cancel(true)' on
your AsyncTask (if you're using AsyncTask).

Network I/O is usually (immediately) interrupted by Thread interruptions.

--- Anton.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »