【发布时间】:2017-05-08 19:45:18
【问题描述】:
有三个活动A,B,C,在活动A中,一个意图打开活动B。在活动B上调用startActivityForResult并打开C。但是在C中调用setResult之后它返回到活动A而不是B 我正在复制我的活动代码,我正在调用开始活动创建事件
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_FILE) {
if (resultCode == Activity.RESULT_OK) {
alertDialogBox.dismiss();
Intent image = new Intent(CreateEventActivity.this, CropImageActivity.class);
image.putExtra("data", data.getData().toString());
startActivityForResult(image, 2);
}
}
if (requestCode == 2) {
if (resultCode == Activity.RESULT_OK) {
String bt = data.getStringExtra("result");
file_path = data.getStringExtra("filepath");
testPath = new File(file_path);
Log.e("desti", testPath.toString());
Log.e("destpat", testPath.getAbsolutePath());
try {
testPath.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
try {
byte[] encodeByte = Base64.decode(bt, Base64.DEFAULT);
bitmap2 = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
// imageforUpload = getStringImage(bitmap2);
BitmapFactory.Options options = new BitmapFactory.Options();
// down sizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 8;
final Bitmap bitmaptest = BitmapFactory.decodeFile(file_path, options);
imgCropped.setVisibility(View.VISIBLE);
imgCropped.setImageBitmap(bitmaptest);
} catch (Exception e) {
e.getMessage();
}
}
}
}
我将数据返回给父级的第二个活动cropActivity
private final CropCallback mCropCallback = new CropCallback() {
@Override
public void onSuccess(Bitmap cropped) {
int height = cropped.getHeight();
int width = cropped.getWidth();
if (height<400||width<400){
Toast.makeText(getApplicationContext(),"this image cat be cropped",Toast.LENGTH_SHORT).show();
}else {
Bitmap bitmap = Bitmap.createBitmap(cropped, 0, 0, 400, 400);
imgtest.setImageBitmap(bitmap);
SaveImage(bitmap);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
String temp = Base64.encodeToString(b, Base64.DEFAULT);
Intent returnIntent = new Intent();
returnIntent.putExtra("result", temp);
returnIntent.putExtra("filepath", filePath);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}
}
请帮我解决这个问题,返回页面是另一个活动
【问题讨论】:
-
你在调用Activity C之前完成Activity B了吗?
-
@sohanshetty no
-
请提供类名,这样从哪个类调用哪个类就清楚了
-
@JoseAntony 当您使用 StartActivityForResult 开始一个活动时,它来自哪个活动?因为我看到你已经在 OnActivityResult 中实现了代码
-
确保在执行 startActivityForResult(yourIntent, SELECT_FILE); 之前或之后没有调用 finish();
标签: android android-intent android-activity startactivityforresult