Search code examples
androidbroadcastreceiver

Android connectivity change broadcast order


I've declared android.net.conn.CONNECTIVITY_CHANGE in my manifest so I can be notified if the user connectivity changes.

I'm receiving more than one broadcast for the same event. The following information (print of intent.getExtras()) was retrieved when I had the mobile connection on and wifi of and than turned the wifi on.

[ networkInfo => NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "HOME", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; networkType => 1; inetCondition => 0; extraInfo => "HOME"; ]

[ networkInfo => NetworkInfo: type: mobile[UMTS], state: DISCONNECTED/DISCONNECTED, reason: dataDisabled, extra: web.network.de, roaming: true, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; networkType => 0; otherNetwork => NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "HOME", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; reason => dataDisabled; inetCondition => 0; extraInfo => web.network.de; ]

[ networkInfo => NetworkInfo: type: WIFI[], state: CONNECTED/CONNECTED, reason: (unspecified), extra: "HOME", roaming: false, failover: false, isAvailable: true, isConnectedToProvisioningNetwork: false; networkType => 1; inetCondition => 0; extraInfo => "HOME"; ]

Is it possible to receive first the disconnect event and than the connect event?


Solution

  • As far as I know, that is not possible. I think it is related to the fact that Android firstly try to connect through WIFI before disconnecting the mobile network (preventing the user from losing connectivity if the connection fails).

    Anyway, you can always save the info you receive and then process it as you want. Just rethink your approach, probably you won't need to receive that info in order.