As I pointed out in my previous post, the polling occurs only when the
application is active and on screen.  It starts/stops in onResume/
onPause - so I am not sure how this is going to limit battery life
unless the user forces the application to remain active for hours at a
time.

Could you please explain to me why, with a solid wi-fi signal and
connection to a local access point, my URLConnections would ever throw
an exception unless there is a problem with the remote website?  Are
the implementations of these APIs that brittle?  Is the hardware
really that flaky?

Are there other APIs that bang on the hardware until it works, without
throwing exceptions?  Am I doing something wrong?  Or is this level of
unreliability, even over local wi-fi, to be expected?

On Nov 24, 10:58 am, Jean-Baptiste Queru <[EMAIL PROTECTED]> wrote:
> Even with a 10-second pause between the end of a response and the next
> request, you're likely to keep the radio (either cell or wifi) turned
> on all the time, since they tend to stay up for about that long even
> when there's no activity before powering back down. That could limit
> the phone's battery life to as little as 3 or 4 hours (with the screen
> constantly off and the CPU idle most of the time).
>
> The APIs that you're using are built on top of a foundation that was
> designed for environments where the conditions that trigger exceptions
> were indeed more exceptional than what you're seeing on a device
> indeed. Such is the cost of making Android compatible with APIs that
> developers are likely to be familiar with.
>
> JBQ
>
> On Mon, Nov 24, 2008 at 8:51 AM, joshv <[EMAIL PROTECTED]> wrote:
>
> > 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 [email protected]
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