-1

I am trying to call AsyncTask from runonUiThread like below

MutiThreadActivity.this.runOnUiThread(new Runnable() {
    public void run() {
        Toast.makeText(MutiThreadActivity.this, "This is Toast!!!", Toast.LENGTH_SHORT).show();
        new backgroundTask(mcon).execute();
    }
});

But doInBackground is not invoked during java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()"

Any one suggest me where am doing wrong.How can i call Asyntask from RunonUithread method in android?

Thanks in advance.

Tushar
  • 85,780
  • 21
  • 159
  • 179
Pinki
  • 21,723
  • 16
  • 55
  • 88
  • `new backgroundTask(mcon).execute();` here is the problem... may be you are calling tost or any Ui element in doInBackground of `backgroundTask` async task..Can you show the code of `backgroundTask` AsyncTask class. – SRB Bans Nov 10 '15 at 06:55

1 Answers1

1

Don't use asycnc task instead use handler or timer it give you illusion of seprate thread by posting in message queue after some delay read about handler it is simple apporch

Nikhil Kamboj
  • 33
  • 1
  • 6