Reputation: 24998
So, I have my AsyncTask
as below:
private class AsyncRetriever extends AsyncTask<IotdHandler,Void,IotdHandler>{
ProgressDialog pDialog;
@Override
protected void onPreExecute(){
pDialog = new ProgressDialog(getApplicationContext());
pDialog.setMessage(getResources().getString(R.string.toast_msg1));
pDialog.show();
}
//------------------------------------------------------------------------------
This is an inner class of the MainActivity
. However, LogCat flags pDialog.show()
as an error.
It says, Unable to start activity ComponentInfo.
How do I solve this?
Upvotes: 1
Views: 2384
Reputation: 619
private class AsyncRetriever extends AsyncTask<IotdHandler,Void,IotdHandler>{
ProgressDialog pDialog;
Context mcontext;
public AsyncRetriever(Context c){
mcontext=c
}
@Override
protected void onPreExecute(){
pDialog = new ProgressDialog(mcontext);
pDialog.setMessage(getResources().getString(R.string.toast_msg1));
pDialog.show();
}
pass the context of calling class in this constructor
Upvotes: 1
Reputation: 12933
A ProgressDialog needs an Activity Context. Try this:
pDialog = new ProgressDialog(YourActivity.this);
Upvotes: 3