how can I save a bitmap with onRetainNonConfigurat

2019-02-13 20:12发布

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条回答
Fickle 薄情
2楼-- · 2019-02-13 20:27

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");
  }
查看更多
登录 后发表回答