I have three activities
MessagesAttachPhotoActivity
MessageGalleryFolderSelectorActivity
ImagePickerActivity
MessagesAttachPhotoActivity
calls MessageGalleryFolderSelectorActivity
with startActivityForResult()
.
MessageGalleryFolderSelectorActivity
activity displays the photo folders on the phone and one selects a folder.
ImagePickerActivity
is then called with setActivityForResult()
. Once an image is selected from ImagePickerActivity
, it is passed back to MessagesAttachPhotoActivity
via MessageGalleryFolderSelectorActivity
.
When I run the app for the first time, everything works fine. However, if I try to select an image again afterwards, MessageGalleryFolderSelectorActivity
does not close after setResult()
.
I have tried calling finish()
, this.finish()
, ((Activity)getApplicationContext()).finish()
, and super.onBackPressed()
without success.
Why does the activity not close on successive runs?
Here is my code:
Calling MessageGalleryFolderSelectorActivity:
Intent intent;
Bundle arguments = new Bundle();
Bundle bundle;
intent = new Intent(this, MessageGalleryFolderSelectorActivity.class);
bundle = new Bundle();
bundle.putInt(Constants.INTENT_EXTRA_LIMIT, Constants.IMAGES_SELECT_LIMIT);
bundle.putInt("Request", MessageThread.MessageType.IMAGE);
intent.putExtras(bundle);
startActivityForResult(intent, MessageThread.MessageType.IMAGE);
ImagePickerActivity:
imagesIntent.putExtra(ImagePickerActivity.INTENT_EXTRA_MODE,
ImagePickerActivity.MODE_MULTIPLE);
imagesIntent.putExtra(ImagePickerActivity.INTENT_EXTRA_LIMIT, 10);
imagesIntent.putExtra(ImagePickerActivity.INTENT_EXTRA_SHOW_CAMERA, false);
imagesIntent.putExtra(ImagePickerActivity.INTENT_EXTRA_ALBUM,album);
//imagesIntent.putExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES, images);
startActivityForResult(imagesIntent, MessageThread.MessageType.IMAGE);
Passing data back to MessageGalleryFolderSelectorActivity:
Intent data = new Intent();
data.putParcelableArrayListExtra
(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES, selectedImages);
data.putExtra(ImagePickerActivity.INTENT_EXTRA_ALBUM,album);
setResult(RESULT_OK, data);
finish();
return true;
Trying to pass data back to the initial calling activity but this activity does not close MessageGalleryFolderSelectorActivity:
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
ArrayList<Image> selectedImages = data.getParcelableArrayListExtra
(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
String album = data.getStringExtra(ImagePickerActivity.INTENT_EXTRA_ALBUM);
Intent intent = new Intent();
intent.putExtra(ImagePickerActivity.INTENT_EXTRA_ALBUM, album);
intent.putParcelableArrayListExtra
(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES, selectedImages);
setResult(Activity.RESULT_OK, intent);
this.finish();
return;
} else if (resultCode == RESULT_CANCELED) {
}
}
return true;
does after finish() ? – Maemaeander