I am checking to see if my app has a network connection:
public boolean isOnline(){
ConnectivityManager conMgr = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
if ( conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED
|| conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING ) {
return true;
}
else if ( conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED
|| conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED) {
return false;
} else {return false;}
}
Whenever I rotate my screen between landscape and portrait this method returns false. It makes me wonder if Network connections are getting killed during the rotation?
No… your network connections don’t get killed during rotation. Probably, what is going on is that you are not saving the boolean value of the connection state, so when the handset is rotated that value gets to its default (false). Check this thread to know how to save the state:
How do I save an Android application’s state?