I know that it's possible to call the method getDialog.dismiss if I use AsyncTask as an inner class but due to the amount of code in the class I decided to have another class for AsyncTask now if I try calling the method it says that Non-static method 'getDialog()' cannot be referenced from a static context. How can I make it work?
public class BackgroundImageResize extends AsyncTask<Uri, Integer, byte[]>
{
Bitmap mBitmap;
byte[] mUploadBytes;
Context context;
public BackgroundImageResize(Context ctx) {
context = ctx.getApplicationContext();
}
public BackgroundImageResize(Bitmap bitmap) {
if (bitmap != null) {
this.mBitmap = bitmap;
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
Toast.makeText(context, "compressing image",
Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected byte[] doInBackground(Uri... params) {
try {
mBitmap =
MediaStore.Images.Media.getBitmap(context.getContentResolver(),
params[0]);
} catch (IOException e) {
e.printStackTrace();
}
byte[] bytes;
bytes = getBytesFromBitmap(mBitmap, 70);
return bytes;
}
@Override
protected void onPostExecute(byte[] bytes) {
super.onPostExecute(bytes);
mUploadBytes = bytes;
progressBar.setVisibility(View.INVISIBLE);
//execute the upload task
ChooseImageActivity.mOnInputListener.sendInput(mUploadBytes);
ChooseImageActivity.getDialog().dismiss();
}
public static byte[] getBytesFromBitmap(Bitmap bitmap, int quality) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
return stream.toByteArray();
}
}