From f13897cc8e1ac9537a563d15c51d2f14bd89adfd Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Sat, 3 Sep 2016 19:54:13 -0700 Subject: [PATCH] Fix snackbar not showing when alarms are created on 21+ --- .../philliphsu/clock2/util/AlarmController.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/util/AlarmController.java b/app/src/main/java/com/philliphsu/clock2/util/AlarmController.java index b80db3b..74f15e4 100644 --- a/app/src/main/java/com/philliphsu/clock2/util/AlarmController.java +++ b/app/src/main/java/com/philliphsu/clock2/util/AlarmController.java @@ -219,10 +219,21 @@ public final class AlarmController { return pi; } - private void showSnackbar(String message) { + private void showSnackbar(final String message) { // Is the window containing this anchor currently focused? - if (mSnackbarAnchor != null && mSnackbarAnchor.hasWindowFocus()) { - Snackbar.make(mSnackbarAnchor, message, Snackbar.LENGTH_LONG).show(); +// Log.d(TAG, "Anchor has window focus? " + mSnackbarAnchor.hasWindowFocus()); + if (mSnackbarAnchor != null /*&& mSnackbarAnchor.hasWindowFocus()*/) { + // Queue the message on the view's message loop, so the message + // gets processed once the view gets attached to the window. + // This executes on the UI thread, just like not queueing it will, + // but the difference here is we wait for the view to be attached + // to the window (if not already) before executing the runnable code. + mSnackbarAnchor.post(new Runnable() { + @Override + public void run() { + Snackbar.make(mSnackbarAnchor, message, Snackbar.LENGTH_LONG).show(); + } + }); } } }