title: Detecting network connectivity on Android?
body: <p>OS: Android</p>
  
  <p>Given: User has stated that they wish to remain connected to app's server to receive updates, etc.</p>
  
  <p>Goal: To ensure that users are connected to app's server even when app is in background state.</p>
  
  <p>Question: One problem has been occasional disconnects from the network. If a user loses data network connectivity (loss of 2G, 3G, WiFi) and then later regains connectivity, our app is left without a connection. I am currently trying to make use of <a href="http://developer.android.com/reference/android/telephony/PhoneStateListener.html" rel="nofollow"><code>PhoneStateListener</code></a>'s in order to detect various network changes and thereby restart connectivity with the server when appropriate. On my Nexus One (2.1), I find that <code>onSignalStrengthsChanged</code> and <code>onDataConnectionStateChanged</code> aren't called except when the listeners are originally registered, but not afterwards. The listeners are registered inside of a Service so they are continuously listening as long as the Service is alive (which we can assume to be 'forever' for purposes of this question).  Has anyone else had any issues with listening to the state of the Data Connection? </p>
  
  <p><code>onServiceStateChanged</code> seems to be the most reliable so far, but I wanted to know if people have had success with the other listeners as well.</p>