I am writing a simple app that set a image to a ImageView
through an Intent
calling the camera. But when I change the orientation the image disappears. I've already tried this questions Q1, Q2. The previous questions suggest either use onSaveInstanceState
or Retaining an Object During a Configuration Change.
But in the Android docs I've read:
you might encounter a situation in which restarting your application and restoring significant amounts of data can be costly and create a poor user experience
So, if a Bitmap
is consider to be a “significant amount of data” I will need to use setRetainInstance
, but in the docs says:
While you can store any object, you should never pass an object that is tied to the Activity, such as a Drawable, an Adapter, a View or any other object that's associated with a Context
What approach should I use to be able to restore the Image on a orientation change?
What I've done so far
private ImageView mPhotoImgage;
private Bitmap mCameraData;
onCreate {
mPhotoImgage = (ImageView) findViewById(R.id.photoResultImage);
if (savedInstanceState != null){
mPhotoImgage.setImageBitmap((Bitmap)savedInstanceState.getParcelable(IMAGE_RESOURCE));
}
}
onResume{
if (mCameraData != null){
mPhotoImgage.setImageBitmap(mCameraData);
}
super.onResume();
}
onSaveInstanceState{
outState.putParcelable(IMAGE_RESOURCE, mCameraData);
super.onSaveInstanceState(outState);
}
But after two orientation changes the image disappears.