Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait to Snackbar ? I want to know when it is closed

I want to get informed when Snackbar is closed.
In an activity I use Snackbar and then I call another activity and I want to show Snackbar and when it has been already closed want to startActivity(NextActivity).
How could I manage it?

like image 463
Mikheil Zhghenti Avatar asked Dec 24 '22 10:12

Mikheil Zhghenti


2 Answers

Snackbar.make(view, "Some text", Snackbar.LENGTH_SHORT)
            .setCallback(new Snackbar.Callback() {
                @Override
                public void onDismissed(Snackbar snackbar, int event) {
                    super.onDismissed(snackbar, event);

                    startActivity(this, NextActivity.class);
                }
            }).show();
like image 92
RockerFlower Avatar answered Jan 05 '23 20:01

RockerFlower


Define an action

.setAction("Go To Next Activity", mOnClickListener);

define onClickListenet as follows:

mOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackBar.dismiss(); // to close the snackbar
                // startActivity(nextActivityIntent)
            }
        };

More Info Here

like image 42
AndroidMechanic - Viral Patel Avatar answered Jan 05 '23 22:01

AndroidMechanic - Viral Patel