If you are waiting for a result from another activity the best thing is to save the parameters as shared preferences and then load them back in the previous activity during onResume. In this way the data won't be lost due to the re-create of the activity that contains the onActivityResult.
Then, for the first activity PictureList, the code changed into this:
bPictureRequested = true;
bPictureReceived = false;
appSharedPreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
preferencesEditor = appSharedPreferences.edit();
preferencesEditor.putBoolean("bPictureReceived", bPictureReceived);
preferencesEditor.commit();
Intent myIntent = new Intent(PictureList.this, AddPictures.class);
Bundle b = new Bundle();
b.putInt("iEntry", clickCounter);
b.putBoolean("bAddPicture", true);
b.putBoolean("bEditPicture", false);
myIntent.putExtras(b);
startActivity(myIntent);
and into onResume I added the following lines in order to get the result:
if(bPictureRequested){
appSharedPreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
bPictureReceived = appSharedPreferences.getBoolean("bPictureReceived", false);
if(bPictureReceived){
iReturnedEntry = appSharedPreferences.getInt("iReturnedEntry", 0);
// Reset the flags
bPictureRequested = false;
bPictureReceived = false;
preferencesEditor = appSharedPreferences.edit();
preferencesEditor.putBoolean("bPictureReceived", bPictureReceived);
preferencesEditor.commit();
}
}
Now, for the other activity AddPictures I left the same part that gets the previous parameters by value but changed the way it returs de data using shared preferences:
appSharedPreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
preferencesEditor = appSharedPreferences.edit();
preferencesEditor.putBoolean("bPictureReceived", true);
preferencesEditor.putInt("iReturnedEntry", iEntry);
preferencesEditor.commit();
finish();
Now everything is working fine.