Thread safe way of displaying a Toast Message For AsyncTask
suggest changeIf you don’t want to extend Application and keep your toast messages thread safe, make sure you show them in the post execute section of your AsyncTasks.
public class MyAsyncTask extends AsyncTask <Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// Do your background work here
}
@Override
protected void onPostExecute(Void aVoid) {
// Show toast messages here
Toast.makeText(context, "Ding! Your Toast is ready.", Toast.LENGTH_SHORT).show();
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents