I have an android app that performs network connections on opening the app and disconnects and removes the networks on closing it.. If the device was initially on 3G, opening and closing the app performs the right connection/disconnection actions.
If the device was initially on WiFi, then opening the app connects to the network but closing the app disconnects from the networks and device falls back to 3G.
It should essentially fall back to the WiFi that the device was on before opening the app.. And the app doesn't disconnect/remove the WiFi that the device was on originally..
Below is a piece of sample code that performs disconnection:
// remove the configuration (and disconnect, if connected)
Log.i(TAG, "removing app network = " + ssid);
boolean b = wifi.removeNetwork(wc.networkId);
assert (b);
// Enable the original WiFi that the device
String deviceInitialSSID = "TEST_WLAN";
previousNetId = wc.networkId;
wifi.setWifiEnabled(true);
wifi.enableNetwork(previousNetId, true);
The above code is executed in onStop()
of the app. The calls to enable the network return true but it does not enable the previous WiFi on the device, in real.
Please advice. Thanks in advance..