have three Activity A,B,C, in Activity A an intent opens Activity B.On activity B startActivityForResult is called and opens C. but after calling setResult in C it is returning to Activity A not to B i am copying my activity code where iam calling start activity create event
@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();
}
}
}
}
second activity cropActivity where i am returning data to parent
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();
}
}
please help me to solve this ,the returning page is another activity
Alternatively you can follow below solution(If you wish), instead of using startActivityForResult() you can use onNewIntent() as a callback method.
Step 1: Declare launchMode of your 'CreateEventActivity' as "singleTask" in your AndroidManifest.xml
Example:
Step 2: Override onNewIntent() in your 'CreateEventActivity'
Example:
Step 3: How to trigger this callback Simply use startActivity(), that is startActivity(B,C) and Once 'Activity C' works done startActivity(C,B) and call finish() on Activity C
Example
From 'CreateEventActivity'
From 'CropImageActivity'
Note: Don't worry Activity B instance won't create again and again. Try this solution if you not been able to find the issue w.r.t startActivityForResult().