mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-02 15:15:09 +00:00
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
This commit is contained in:
@@ -191,7 +191,7 @@ public class SharePlugin extends Plugin implements ReceiveFileRunnable.CallBack
|
|||||||
String text = np.getString("text");
|
String text = np.getString("text");
|
||||||
ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
cm.setText(text);
|
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
|
@WorkerThread
|
||||||
|
Reference in New Issue
Block a user