问题
In my class view phone cam will be opened and programme shows the bitmap after user take photo from phone cam but at the same time the user rotates the screen to "landscape" bitmap will disappear and activity's oncreate() will load again and then camera will be opened again.
I didnt know save bitmap with onRetainNonConfigurationInstance() or onSaveInstanceState().
The question is this how can I save the bitmap(taken from phone cam) before user rotates the phone so that even if phone is landscape mode same bitmap will be showed in the screen??
---EDIT--- Adding to AndroidManifest.xml is a good way to obtain saving state?
回答1:
Save it onSaveInstanceState:
@Override
public void onSaveInstanceState(Bundle toSave) {
super.onSaveInstanceState(toSave);
toSave.putParcelable("bitmap", bitmap);
}
And get it back onCreate:
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
if (savedState != null) bitmap = savedState.getParcelable("bitmap");
}
来源:https://stackoverflow.com/questions/5862937/how-can-i-save-a-bitmap-with-onretainnonconfigurationinstance-for-screen-orien