Issue
I have extended the Application class in my app. In that class, I have a BroadcastReceiver that waits for Connectivity changes. If I switch to airplane mode, it instantly recognizes a connectivity lost and the broadcast is received, however if I lose my data connectivity (ie being underground, etc), it takes a few seconds to a few minutes to fire even though no internet related tasks are successfully completing (even if you try browsing in the browser). Is there a more precise way to find out when internet connectivity is first lost?
Solution
A way to find out when Internet connectivity is lost is to do proper exception checking for network errors.
If a networking exception is thrown (socket timeout, I/O error, etc) you can set the state of the application to disconnected. Of course this only works when you are actively trying to send or receive data over the network.
If connectivity notification is that important you can do periodical checks by using a remote server (ping a google server for example), but this will drain your battery as touching the network too often tends to keep the radio awake and draw power.
Answered By - Vasile Jureschi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.