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.
Related Contents:
- Can an Android Toast be longer than Toast.LENGTH_LONG?
- How do we use runOnUiThread in Android?
- Android – Snackbar vs Toast – usage and difference
- How do you display a Toast from a background thread on Android?
- How to display Toast at center of screen
- What is the Android UiThread (UI thread)
- What does “toast” mean?
- Center text in a Toast
- How can I change default toast message color and background color in android?
- Adding image to Toast?
- How to avoid a Toast if there’s one Toast already being shown
- How do I obtain crash-data from my Android application?
- How to handle screen orientation change when progress dialog and background thread active?
- OnActivityResult method is deprecated, what is the alternative?
- What does it mean to inflate a view from an xml file?
- Android: How to create a Dialog without a title?
- Android Completely transparent Status Bar?
- How to change the floating label color of TextInputLayout
- How can I assign an ID to a view programmatically?
- converting drawable resource image into bitmap
- Allow user to select camera or gallery for image
- Making a Location object in Android with latitude and longitude values
- How to disable gradle ‘offline mode’ in android studio? [duplicate]
- MenuItemCompat.getActionView always returns null
- “unable to locate adb” using Android Studio [duplicate]
- error opening HPROF file: IOException: Unknown HPROF Version
- How to center vector drawable in layer-list without scaling
- Android Studio – ADB Error – “…device unauthorized. Please check the confirmation dialog on your device.”
- Is GUI for Android SDK manager gone?
- Overlap scrolling view with AppBarLayout
- Why there’s a separate MutableLiveData subclass of LiveData?
- EditText onClickListener in Android
- Android ListView Divider
- “minifyEnabled” vs “shrinkResources” – what’s the difference? and how to get the saved space?
- google signIn not working in release mode apk android
- Notification Badge On Action Item Android
- Couldn’t resolve resource @id/visible when using TextInputLayout
- Can VS Code run on Android? [closed]
- Android Studio, Suddenly got GPU Driver Issue when running emulator
- Get string extra from activity Kotlin
- Android Data Binding: visibility on include tag
- How to hide app title in android? [closed]
- Check if user is authenticated for the first time in Firebase Google Authentication in Android
- No resource found that matches the given name ‘@style/Theme.AppCompat.Light’
- RecyclerView is cutting off the last item
- Android Toolbar: small title text in landscape mode
- Why do ListView items not grow to wrap their content?
- Error: “app_name” is not translated in af
- Kotlin Coroutines the right way in Android
- Android Hardware Acceleration – to use or not to use?