I'm trying to resolve some mysterious behavior when my application gets killed when I'm in gallery.
I have such flow:
From Activity_1
I'm startActivityForResult
Activity_2
. From Activity_2
I'm letting user to pick an image from desired source.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Hint", REQUEST_CODE_SELECT_PICTURE);
Sometimes while user is in the gallery (usually when there are lots of apps in the background running) my app gets killed. Without any warning whatsoever - my application process disappears from process list. And when user picks a photo he's able to return to Activity_2
but all previously selected images are lost.
If user presses "Next" at that point app should return to Activity_1
Intent data = new Intent();
data.putStringArrayListExtra(EXTRA_PHOTOS, new ArrayList<String>(selectedPictures));
setResult(RESULT_OK, data);
finish();
But it looks like there is no Activity_1
and app just restarts. No crash, just restart. And user gets back to Activity_1
, but looses all data.
It is very hard to reproduce and is very annoying. Is there a way to prevent such behaviour?