thanks to this answer Android Fragment lifecycle issue (NullPointerException on onActivityResult) I've managed to re-create a scenario when I receive a NPE in my fragment after calling startActivityForResult. So i have
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, PHOTO_SELECT_REQUEST_CODE);
break;
being called from my fragment, then my activity receives onPause, onStop and onDestroy, so the fragment that called startActivityForResult
gets an onDestroy as well. After I pick an image, i get a new onCreate on my activity and then i get a public void onActivityResult
on my original fragment that is now destroyed.
My question is since this is potentially (albeit a rare) situation, how would one restore the entire stack of fragments and objects passed to them and what does one do to prevent the original fragment from leaking?