0

I have a SnackBar that I would like to display on another view after I am done with the current view. It's a send form so when I click the send button, I want the SnackBar to appear on the other activity since the send form one will be closed. Here's the code:

final Snackbar snackSuccess =  Snackbar.make(***ViewToModifyHere?***, "Signal successfully sent.", Snackbar.LENGTH_LONG)
                            .setAction("Action", null)
                            .setDuration(2500);

                    snackSuccess.setAction("Dismiss", new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            snackSuccess.dismiss();
                        }
                    });
                    snackSuccess.setActionTextColor(Color.GREEN);

                    snackSuccess.setCallback(new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            if (event != DISMISS_EVENT_ACTION) {

                            }
                        }
                    });
                    snackSuccess.show();
                    finish();
Montassir Ld
  • 531
  • 4
  • 12
  • This is quoted from the [documentation](https://developer.android.com/reference/android/support/design/widget/Snackbar.html): "They automatically disappear after a timeout or after user interaction elsewhere on the screen, particularly after interactions that summon a new surface or activity. Snackbars can be swiped off screen." You probably will have to use a `Toast` instead. If you really have to show a Snackbar you can send an extra in the intent and show the Snackbar in the other `Activity`. – MohanadMohie Oct 23 '16 at 22:36
  • Cannot send a Snackbar as extra – Montassir Ld Oct 23 '16 at 23:38
  • Don't try to send the `Snackbar`. Send just the information needed to create it in the next `Activity`; e.g., the message text, duration, whatever. – Mike M. Oct 24 '16 at 03:24
  • Exactly as Mike said, just send the information and display a new Snackbar in the next Activity. – MohanadMohie Oct 24 '16 at 09:14
  • Okay, but how does the other activity listen for such information, and know when exactly to show it? – Montassir Ld Oct 24 '16 at 15:00

0 Answers0