The polling happens only while the apps is loaded and displayed on
screen.  The second the screen turns off or another app is loaded, the
polling stops.  It's pretty well behaved in that respect.  Also, I
don't hammer the connection 6 times a minute no matter what - each
thread waits for the previous to finish, waits ten seconds, and then
attempts to connect.

My issue is that URLConnections seem to be so unreliable that
Exceptions seem to be the rule, not the exception.  This might be
something unique to my handset, I only have one, so I can't tell.  It
certainly doesn't happen in the emulator.  I might expect it to happen
if I have a marginal 3G or edge connection - but not when the handset
is literally 3 feet away from the WiFi access point it's using for a
connection.


On Nov 24, 10:00 am, "Andrew Stadler" <[EMAIL PROTECTED]> wrote:
> If your code is going to access a site every 10 seconds, the radio is
> going to, essentially, stay "on" continuously.  This is going to have
> a significant impact on your users' battery life.  Is this definitely
> what you want to do?
>
> On Mon, Nov 24, 2008 at 5:17 AM, joshv <[EMAIL PROTECTED]> wrote:
>
> > I am attempting to write an application that regularly polls data from
> > a publicly available website using a URLConnection.  The code is
> > pretty basic (urlStr contains the URL...)
>
> >                URL url = new URL(urlStr);
> >                URLConnection urlConn = url.openConnection();
> >                urlConn.setConnectTimeout(5000);
> >                BufferedReader in = new BufferedReader(new InputStreamReader
> > (urlConn.getInputStream()));
> >                String line;
> >                while ((line = in.readLine())!=null) {   ....
>
> > Anyway, even when the G1 is connected to the network (verified in
> > browser) this block of code will regularly throw
> > java.net.SocketException: No route to host,
> > java.net.SocketTimeoutException: Socket is not connected (though this
> > is probably because I added a timeout), and many times throw an
> > Exception claiming that it could not resolve the hostname in urlStr -
> > oddly the web browser has no such issues resolving the name.
>
> > The above block of code runs every 10 seconds (or longer if the
> > previous request takes longer), and I'd guess succeeds approximately
> > 25-50% of the time, though it tends to be a bit streaky.  When the
> > connection succeeds, it take less than a second to connect and
> > download the data, it's a very small data set - so the timeout setting
> > should not be an issue.
>
> > The periods of error do not correspond to a loss of connectivity, as I
> > can browser the web at the same time the errors are happening.  This
> > happens whether connected to local wi-fi or 3G.
>
> > Am I doing something wrong, or is network connectivity on the G1 just
> > this flaky?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to