From 087b7ce875ae921094e786be767e64a5def6e4f6 Mon Sep 17 00:00:00 2001 From: Erik Duisters Date: Fri, 7 Dec 2018 11:54:00 +0100 Subject: [PATCH] Make toast work from a background thread Summary: When receiving a text share an attempt is made to show a toast but that results in an exception because the issuing thread is not running a looper. Test Plan: Without this patch applied Share a text with an android device using the plasmoid Result: No toast is displayed and in logcat you will get a: java.lang.RuntimeException: Can't toast on a thread that has not called Looper.prepare() exception With this patch applied again Share a text an android device using the plasmoid Result: The toast is actually displayed even when the activity is not in the foreground Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17400 --- src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index d2a39875..9c5382dc 100644 --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -191,7 +191,7 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack String text = np.getString("text"); ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(text); - Toast.makeText(context, R.string.shareplugin_text_saved, Toast.LENGTH_LONG).show(); + handler.post(() -> Toast.makeText(context, R.string.shareplugin_text_saved, Toast.LENGTH_LONG).show()); } @WorkerThread