Java.Lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

Code

Toast toast = Toast.makeText(mContext, "Something", ToastLength.LENGTH_SHORT);
Exception

Java.Lang.RuntimeException: Can't create handler inside thread 
that has not called Looper.prepare()
Reason

Android basically works on two thread types namely UI thread and background thread.
Toast cannot be called from a non-UI thread.
Solution

RunOnUiThread(() =>
{
    Toast.MakeText(this, "Something", ToastLength.Short).Show();
});



Comments

Popular posts from this blog

SQL Interview Questions and Answers

Generic Interface and Factory Pattern in C#

How to get device info IMEI programmatically in xamarin android