0

My Application looks for the Connectivity-State using a Broadcastlistener. If the Phone is offline, a Snackbar should appear. The Snackbar has an Action, to Open the Networksettings.

If I click on this, my Networksettings were opened. If I don't turn on my Internet and go back to the App, my Snackbar isn't shown again though it is called (Checked it!).

If I set the Snackbar to null and initialise it again, it works!

MainActivity:

@Override
protected void onResume() {
    super.onResume();

    registerReceiver(networkListener, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
}

@Override
protected void onPause() {
    super.onPause();

    unregisterReceiver(networkListener);
}

@Override
public void ToggleSnackbar(boolean ShowHide) {
if (ShowHide) {
    snbInternetState.show();
}
else {
    snbInternetState.dismiss();
}

    bOnline = ShowHide;
}

NetworkListener:

public class NetworkListener extends BroadcastReceiver {

    private SnackbarInterface snbInterface;

    public NetworkListener(SnackbarInterface snbInterface) {
        this.snbInterface = snbInterface;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();

        if (ni == null || !ni.isConnectedOrConnecting()) {
            snbInterface.ToggleSnackbar(true);
        }
        else if (ni != null && ni.isConnected()) {
            snbInterface.ToggleSnackbar(false);
        }
    }

    public interface SnackbarInterface {
        void ToggleSnackbar(boolean ShowHide);
    }
}

Does anybody know how to fix this problem?

Thanks!

the_dani
  • 2,466
  • 2
  • 20
  • 46

1 Answers1

0

I solved the problem by recreating the Snackbar in "onResume()".

the_dani
  • 2,466
  • 2
  • 20
  • 46