how can I save a bitmap with onRetainNonConfigurationInstance() for screen orientation?

北战南征 提交于 2020-01-21 04:49:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!