My application has many classes, worker threads, and background service operations. Notifications can come in from those other threads and they can come in on a service when the app isn't running. I have a utility class where I would like to write a single "SendToast(Context ctx, String message)" method that can handle all of these situations. Is it possible? This SO post comes close, but it won't work for my service messages
// won't work.. I need something that can run given a Context, rather than
// an Activity
public static void ShowToast(final Activity activity,
final String message, int length) {
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show();
}
});