You need to call Toast.makeText(...)
from the UI thread:
activity.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(activity, "Hello", Toast.LENGTH_SHORT).show();
}
});
This is copy-pasted from another (duplicate) SO answer.
More Related Contents:
- How do we use runOnUiThread in Android?
- How do you display a Toast from a background thread on Android?
- Can an Android Toast be longer than Toast.LENGTH_LONG?
- What is the Android UiThread (UI thread)
- Is it possible to use AsyncTask in a Service class?
- Android ViewPager automatically change page
- Sending and Parsing JSON Objects in Android [closed]
- Android Respond To URL in Intent
- Border for an Image view in Android?
- How to write files to assets folder or raw folder in android?
- Clear back stack using fragments
- How to change the color of a CheckBox?
- Store Android SQLite
- java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)
- How to list files in an android directory?
- How to always run a service in the background?
- Android Studio: Gradle sync failed: Could not HEAD ‘…’. Received status code 502 from server: Bad Gateway [closed]
- How do I programmatically set the background color gradient on a Custom Title Bar?
- Handle Button click inside a row in RecyclerView
- Getting error: Could not find class ‘android.app.AppOpsManager’, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zza
- What are the differences between activity and fragment?
- Replacing default Phone app on Android 6 and 7 with InCallService
- Error while starting emulator
- Android List view layout Similar to Google play
- Android different EditText backgrounds for different states using shapes, selector or list
- Android — How to position View off-screen?
- On Android 8.1 API 27 notification does not display
- Android SharedPreferences , how to save a simple int variable [duplicate]
- Recyclerview Adapter and Glide – same image every 4-5 rows
- how to make text view clickable in android?