Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 350
barzos Avatar asked May 02 '11 21:05

barzos


People also ask

How to save data on orientation change?

You can save any Object by Overriding public Object onRetainNonConfigurationInstance () and calling getLastNonConfigurationInstance() in your onCreate method. but if you do this, you have to change your manifest and code, so the normal process for a configuartion change is used.

Which technique is used to handle screen orientation?

The most commonly used values are "orientation" , "screenSize" , "screenLayout" , and "keyboardHidden" : The "orientation" value prevents restarts when the screen orientation changes. The "screenSize" value also prevents restarts when orientation changes, but only for Android 3.2 (API level 13) and above.

How to stop orientation change in Android studio?

In Android Studio 1 one simple way is to add android:screenOrientation="nosensor" . This effectively locks the screen orientation.

What happens when screen orientation changes in Android?

When you rotate your device and the screen changes orientation, Android usually destroys your application's existing Activities and Fragments and recreates them. Android does this so that your application can reload resources based on the new configuration.


1 Answers

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");
  }
like image 113
dmon Avatar answered Sep 22 '22 14:09

dmon