I have around seven activities in my android project and on all seven activities, i want to monitor network disconnection.I have created a networkreceiver
class which receive notification when wifi is enabled or disabled.
public class NetworkReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent arg1) {
ConnectivityManager conMan = (ConnectivityManager) context.
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI)
Log.d("WifiReceiver", "Have Wifi Connection");
else
Log.d("WifiReceiver", "Don't have Wifi Connection");
}
}
and in manifest
<receiver android:name=".NetworkReceiver" >
<intent-filter>
<action android:name="android.net.wifi.STATE_CHANGE" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
My question is , Since i created it as a seperate class, i am not getting how to get notify on every activity that wifi is not enable.or do i have to create a network receiver as inner class in every activity.