Create a Handler Inside Thread in Android
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 s开发者_开发百科olve this problem?
Thanks in advance.
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();
}
}
精彩评论