The reason the onCreate() is called again isn't always because your device is low in memory, one of the most common reasons is the change in orientation which causes the activity to recreate so you can try putting this in your manifest file:
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
however, if you experiment enough with your code and come to conclusion that it is caused by android destroying the activity because of memory shortage then here is a work around you can use to correctly restore your activity.
YourObject mObject;
.
.
.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mObject.setImageUri(bla..); //Store image Uri and other values in mObject
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
if (mObject != null) {
//save your object which contains data like image uri
savedInstanceState.putSerializable(KEY, mObject);
}
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
YourObject obj = (YourObject) savedInstanceState.getSerializable(KEY);
if(obj != null)
mObject = obj;
}
and finally, in the onResume, read your stored data back from mObject if its not null
@Override
protected void onResume() {
super.onResume();
if(mObject != null) {
//set image to imageView using the stored Uri
setImage(imageView, mObject.getImageUri());
}
}
Sequence:
OnResume
OnPause
OnSaveInstanceState - Here we save our data in bundle
OnDestroy - Here we lose all our activity data
OnCreate
onRestoreInstanceState - Here we restore our saved data from bundle if any
OnResume - Here we deal with restored data if any