6

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?

barzos
  • 837
  • 3
  • 16
  • 25

1 Answers1

9

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");
  }
dmon
  • 30,048
  • 8
  • 87
  • 96
  • but programme says that "bitmap cannot be resolved to a variable". What can I do? – barzos May 02 '11 at 22:19
  • 1
    Sounds as though you need to read up on programming in general. You didn't post any code so dmon gave you a generic example, with a generic variable name of `bitmap`. Substitute your real variable name for the bitmap from the camera. If what I'm saying doesn't make sense, please take a look at some general programming information online. – Brian Dupuis May 02 '11 at 22:25
  • I tried before as you told but also when I write my real variable name of bitmap, the result is same – barzos May 02 '11 at 22:32
  • Also Do I need use onRestoreInstanceState() with onSaveInstanceState() ? – barzos May 02 '11 at 22:51
  • Nope. See http://stackoverflow.com/questions/4096169/onsaveinstancestate-and-onrestoreinstancestate – dmon May 02 '11 at 23:18
  • Really a bad practice, you will get TransactionTooLargeException error – Pulkit Aug 28 '17 at 03:37