So i am trying to launch a progress dialog from an async task.
in my main activity i am invoking the async task like so:
new OCRScanAsyncTask(getApplication().getApplicationContext()).execute();
also tried:
new OCRScanAsyncTask(getBaseContext()).execute();
my asyncTask looks like this:
public class OCRScanAsyncTask extends AsyncTask<String, Integer, Boolean> {
/* (non-Javadoc)
* @see android.os.AsyncTask#doInBackground(Params[])
*/
private ProgressDialog progressDialog;
private String TAG ="OCRAsyncTask";
private String IMAGE_PATH = Environment.getExternalStorageDirectory() + "/bcCardReader/tmp/tmpCrd.jpg";
public static final String DATA_PATH = Environment
.getExternalStorageDirectory().toString() +"/bcCardReader/tmp/";
private String lang = "eng";
private Context context;
public OCRScanAsyncTask(Context c){
Log.v(TAG, "*****************CONSTRUCTING");
context = c;
progressDialog = new ProgressDialog(context);
}
@Override
protected void onPreExecute(){
super.onPreExecute();
Log.v(TAG, "pre exe");
progressDialog.setTitle("Please Wait");
progressDialog.setMessage("Performing Character Recognition");
progressDialog.setIndeterminate(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
progressDialog.show();
}
............
my error looks like this:

Most likely is problem with
Contextvariable. So my first suggestion is replace your linewith
Note: I recommend to you to show
progressDialogbefore you will startAsyncTask.