I have many activities, and I have broadCastReceiver that I registered in manifest for check Connectivity.
I would like show Snackbar
in current activity when I lost internet connection
I registered my receiver in manifest:
<receiver android:name="com.itmind.spac.spacapp.services.ConnectivityChangeReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
And in BroadCast class:
public class ConnectivityChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
ConnectivityManager cm =(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo()!=null){
Toast.makeText(context, "Connected to Internet", Toast.LENGTH_LONG).show();
}
else{
/** I WOULD CREATE A SNACKBAR FOR ALL ACTIVITIES, OR FOR MY CURRENT ACTIVITY */
Toast.makeText(context, "No Connected to Internet", Toast.LENGTH_LONG).show();
}
}
}