Raising a toast from AsyncTask

I am trying to raise a toast from asynctask, but I have problems setting the parameters. I'm toasts from onProgressUpdate, so I'm in the UI thread, which I think is correct. I think I'm wrong in the context parameter, what do I need to pass as a value?

EDIT: code display below

    @Override
protected void onProgressUpdate(String... strings){
    Toast toast = Toast.makeText(MainActivity.this, strings[0], Toast.LENGTH_LONG);
    toast.show();
}

MainActivity.this says: "No instance of type MainActivity is available in scope." I am not sure what to convey as context.

thank

+5
source share
3 answers

Context, getApplicationContext() MainActivity AsyncTask. EboMike, MainActivity.this , AsyncTask .

+4

, , MainActivity.this , . - AsyncTask , , . getApplicationContext , , .

+2

onProgressUpdate(). , . Eclipse , , MainActivity.this . ? , , , , .

, , , , . - :

Activity.runOnUiThread(Runnable)
View.post(Runnable)
View.postDelayed(Runnable, long)

-.

-1

All Articles