我正在尝试在我的AsyncTask类中使用Biokys crop image library,出于某种原因,在尝试为结果启动裁剪图像类时,我收到错误。
我查了会导致这种情况的原因,人们建议你应该使用:
YourClassName.this.startActivityForResult(Intent, RESULT_CODE);
但这不适合我。
如果有人能够解释为什么会发生这种情况,我将不胜感激。
类别:
private void runCropImage() {
Intent intent = new Intent(context, CropImage.class);
// tell CropImage activity to look for image to crop
Bitmap filePath = bmImg;
intent.putExtra(CropImage.IMAGE_PATH, filePath);
// allow CropImage activity to rescale image
intent.putExtra(CropImage.SCALE, true);
// if the aspect ratio is fixed to ratio 3/2
intent.putExtra(CropImage.ASPECT_X, 3);
intent.putExtra(CropImage.ASPECT_Y, 2);
// start activity CropImage with certain request code and listen
// for result
SetWallpaperAsync.this.startActivityForResult(intent, REQUEST_CODE_CROP_IMAGE);
}
答案 0 :(得分:3)
而不是SetWallpaperAsync.this
使用(Activity) context
这样:
((Activity) context).startActivityForResult(intent, REQUEST_CODE_CROP_IMAGE);
答案 1 :(得分:0)
您是否尝试过更换
Intent intent = new Intent(context, CropImage.class);
与
Intent intent = new Intent(YourClassName.this, CropImage.class);