How to hide a Snackbar and show a new one right after that?

I show a Snackbar indefinitely. If the Bluetooth gets turned off, I want to hide it and show a new one to tell the users that they have to turn on the bluetooth. I dismiss the previous Snackbar before showing the new one, but still only the old Snackbar stays visible.

activeSnackbar.dismiss();
Snackbar.make(parent, "Bluetooth is off", Snackbar.LENGTH_INDEFINITE)
            .setAction("Turn on", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    BluetoothUtil.enableBluetooth(main);
                }
            }).show()

How can I make the old Snackbar disappear before showing the new one?

Upvotes: 4

Views: 3081

Answers (1)

GoRoS
GoRoS

Reputation: 5375

You don't have to do anything special for it, just make the next Snackbar and show it, it will make the old one disappear without calling the dismiss method.

Upvotes: 6

Related Questions