具有三个活动a,b,c,在活动a a意图打开活动b.on活动b startActivityForresult被调用并打开C。但是在C中调用SetResult C中,它正在返回活动a不b我正在复制我的活动代码,其中IAM调用开始活动创建事件
@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();
}
}
}
}
第二个活动作物,我将数据返回父母
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();
}
}
请帮助我解决这个问题,返回页面是另一个活动
希望您必须更正请求
Intent returnIntent = new Intent();
returnIntent.putExtra("result", temp);
returnIntent.putExtra("filepath", filePath);
setResult(2, returnIntent);
finish();
因为您在这里提到了同样的内容
Intent image = new Intent(CreateEventActivity.this, CropImageActivity.class);
image.putExtra("data", data.getData().toString());
startActivityForResult(image, 2);
First a fall you need to check the flow of control of your code, whether its going in correct blocks or not.
替代您可以按以下解决方案(如果需要),而不是使用 startActivityForresult()您可以使用 onnewintent()作为回调方法。
You need to follow few steps.
步骤1:您的' createEeventActivity 'as as" singletask "在您的androidmanifest.xml
中示例:
<activity android:name=".CreateEventActivity" android:launchMode="singleTask"/>
步骤2: Override onNewIntent() 示例: 步骤3:如何触发此回调 只需使用startActivity(),即起始性(b,c),一旦"活动c"工作完成了起始性(C,b),并且在活动c 示例 来自'createEventActivity' 来自'prapimageactivity ' 注意:不用担心活动b实例不会一次又一次创建。如果您找不到W.R.T StartActivityForresult()的问题,请尝试此解决方案。 @Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent!=null)
{
// YOU CAN CHECK FLAGS OVER HERE, BY PASSING THE VALUES THROUGH INTENTS from different other activities
if(intent.getBooleanExtra("IS_COMING_FROM_CROP_ACTIVITY",false)
{
// HANDLE YOUR STUFF
}
}
}
startActivity(new Intent(CreateEventActivity.this, CropImageActivity.class));
startActivity(new Intent(CropImageActivity.this, CreateEventActivity.class));
finish();