q126y q126y - 2 years ago 135
Android Question

How does calling Snackbar.make() from non-UI thread works?

I call

from background thread of
, it works. I thought UI operations are allowed from UI thread only[1]. But that definitely is not the case here.

How does it work? If there are certain exceptions to statement 1, what are they?

Answer Source

Snackbar calls under the hood a SnackbarManager, which operates on the main looper:

private SnackbarManager() {
    mLock = new Object();
    mHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case MSG_TIMEOUT:
                    handleTimeout((SnackbarRecord) message.obj);
                    return true;
            return false;

Link: SnackbarManager.java

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download