I do not know a better solution. Romain Guy describes the same approach (checking the status of savedInstance or other objects that you pass for null).
In the new action, in onCreate (), all you have to do to get the object back is to call getLastNonConfigurationInstance (). In Photostream, this method is called, and if the return value is not null, the grid is loaded with a list of photos from the previous Activity:
private void loadPhotos() { final Object data = getLastNonConfigurationInstance(); // The activity is starting for the first time, load the photos from Flickr if (data == null) { mTask = new GetPhotoListTask().execute(mCurrentPage); } else { // The activity was destroyed/created automatically, populate the grid // of photos with the images loaded by the previous activity final LoadedPhoto[] photos = (LoadedPhoto[]) data; for (LoadedPhoto photo : photos) { addPhoto(photo); } } }
When I'm lazy, I just turn off the recreation of the orientation-changing Activity. As described in How to disable orientation changes on Android?
source share