0

I tried to show the toast from the thread.

Toast.makeText(activity.getApplicationContext(), "This is the Toast message", Toast.LENGTH_LONG).show();

but throws the exception

java.lang.RuntimeException:Can't create a handler inside thread that has not called Looper.prepare().

How do I solve this problem? I have put the Looper.myLooper().prepare(); before the Toast.makeText(....).show();

When I have done this it doesn't throw the exception but does not show any toast message.

So how do I solve this problem?

Thanks in advance.

Kindle Q
  • 944
  • 2
  • 19
  • 28
Bikesh
  • 91
  • 4
  • 13

1 Answers1

0

You can create your Toast message in onPostExecute of Async Task.. Try this..

protected void onPostExecute(Void result) {
  Toast.makeText(ActivityName.this,"Your Text", Toast.LENGTH_SHORT).show(); 
  if (this.dialog.isShowing()) {
    this.dialog.dismiss();
  }
}
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
Venky
  • 11,049
  • 5
  • 49
  • 66