I’m having a hard time with the screen orientation in Android. I have an activity which captures a signature after the user draws his signature on the device. And for that activity I am passing a parceable object and I get it in oncreate. When the activity changes the orientation sometimes the activity cannot get the parceable object and gives an exception. I tried using a static object for the parceable object but no use. I tried onsaveinstance state method and onRetainNonConfigurationInstance methods as well.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signature_capture_view);
Bundle bundle = getIntent().getExtras();
info = bundle.getParcelable("info");
logo= (Bitmap) bundle.get("logo");
}
And my save instance state method is like this;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putParcelable("info", info);
super.onSaveInstanceState(outState);
}
From the onconfiguration changed method i call the setcontentview method to set a fresh layout.
@Override
public void onConfigurationChanged(Configuration newConfig) {
setContentView(R.layout.signature_capture_view);
super.onConfigurationChanged(newConfig);
}
Sometimes when the orientation changes an out of memory exception occurs from the setcontentview method.
Any help would be greatly appreciated. Thanks in advance.
I finally found the answer to my out of memory, In my signature drawing view I did not check the bitmap in the view for null and everytime the device changes the orientation it creates the bitmap inside the view. And it generates the OOM. So i inserted a null check for the bitmap and the oom disappeared. Thanks for the quick replys guys.