Search code examples
androidandroid-networking

Why Android can handle only one active Internet connection?


I encountered with strange issue in Android.I use this code to get the information about all Internet connections:

    NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
    for (NetworkInfo networkInfo : info)
    {
        Log.d("LOG","networkInfo = " + networkInfo);
    }

I test this on my device on which I turn on WiFi connection and have an active mobile Internet (EDGE). But in shows:type: mobile[EDGE], state: DISCONNECTED/DISCONNECTED and type: WIFI[], state: CONNECTED/CONNECTED but when I turn off WiFi it shows type: mobile[EDGE], state: CONNECTED/CONNECTED.

Can someone explain me this strange behavior.It seems Android can handle only one connection in spite of there are several ones active (and it always prefer WiFi connection over EDGE). Is there some workaround?Or may be it is a bug?


Solution

  • Can someone explain me this strange behavior.

    Android uses WiFi if it is available. Otherwise, it uses mobile data.

    It seems Android can handle only one connection in spite of there several ones active.

    Android normally only uses one connection at a time. In most of the world, mobile data is metered, and so if WiFi is available, Android uses it, to reduce the cost to the user.

    The OS is capable of using multiple connections at once (see the WiFi hot-spot facility), but for normal operations, only one connection is necessary.