How to use setDuration() method in SnackBar (Android Design Support Library)

Based on the implementation of Snackbar and SnackbarManager, I can confirm Eugene H’s assessment: it’s a bug. From SnackbarManager:

private void scheduleTimeoutLocked(SnackbarRecord r) {
    mHandler.removeCallbacksAndMessages(r);
    mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_TIMEOUT, r),
            r.duration == Snackbar.LENGTH_LONG
                    ? LONG_DURATION_MS
                    : SHORT_DURATION_MS);
}

So, any value that is not LENGTH_LONG results in a short-duration snackbar.

I have filed an issue about it.

Edit: Has been fixed in revision 22.2.1. Check the release notes here

The android docs have NOT been updated yet, but if you jump into the source code you’ll notice that the parameter to the method setDuration(int duration) can either be one of LENGTH_SHORT, LENGTH_LONG, LENGTH_INDEFINITE or a custom duration in milliseconds

Leave a Comment

Hata!: SQLSTATE[08004] [1040] Too many connections