SnackBar still showing when I come back to previous Activity
<p>I have a <code>SnackBar</code> in <code>Activity</code> A, if I click on a <code>Button</code> in <code>Activity</code> A I navigate to <code>Activity</code> B. If I press back immediately, I can see the <code>SnackBar</code> still being show in <code>Activity</code> A.</p>

<p>How to make <code>SnackBar</code> <code>dismiss</code> once user leaves the <code>Activity</code>.</p>

<p>My Effort:</p>

<p>Wrote a generic class which handles creation and dissmissal of SnackBar and</p>

<p>Create SnackBar :</p>

<pre><code>public static Snackbar showSnackBar(View view, int text) {
    if(snackBar != null &amp;&amp; snackBar.isShown()) {
        snackBar.setText(text);
    } else {
        snackBar = snackBar.make(view, text, Snackbar.LENGTH_LONG);
    }
    if (!AppRunningState.isApplicationBroughtToBackgrounds(App.get())) {
        snackBar.show();
    }
    return snackBar;
}
</code></pre>

<p>and in <code>onPause</code>:</p>

<pre><code>@Override
protected void onPause() {
    super.onPause();
    SVSnackBar.dismissSnackBar();
}

public static void dismissSnackBar() {
    if (snackBar != null) {
        snackBar.dismiss();
    }
}
</code></pre>