java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Worker threads are meant for doing background tasks and you can't show anything on UI within a worker thread unless you call method like runOnUiThread. If you try to show anything on UI thread without calling runOnUiThread, there will be a java.lang.RuntimeException
.
So, if you are in an activity
but calling Toast.makeText()
from worker thread, do this:
runOnUiThread(new Runnable()
{
public void run()
{
Toast toast = Toast.makeText(getApplicationContext(), "Something", Toast.LENGTH_SHORT).show();
}
});
The above code ensures that you are showing the Toast message in a UI thread
since you are calling it inside runOnUiThread
method. So no more java.lang.RuntimeException