0

i want to save the contents of an ArrayList of Views "ArrayList". i overriden the method "onSaveInstanceState" as shown below in the code, but at run time i receive the below posted logcat errors . please let em know how to set a list of View objects in a bundle

code:

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Log.w(TAG, "onSaveInstanceState");

    if (this.mListViews != null && this.mListViews.size() > 0) {
        outState.putSerializable(KEY_LIST_OF_VIEWS, this.mListViews);
   }
  }

logcat

java.lang.RuntimeException: Parcel: unable to marshal value android.widget.ImageView{8787bd0 V.ED..... ........ 20,20-1580,2247}
                          at android.os.Parcel.writeValue(Parcel.java:1419)
                          at android.os.Parcel.writeList(Parcel.java:760)
                          at android.os.Parcel.writeValue(Parcel.java:1366)
                          at android.os.Parcel.writeArrayMapInternal(Parcel.java:687)
                          at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
                          at android.os.Bundle.writeToParcel(Bundle.java:1079)
                          at android.os.Parcel.writeBundle(Parcel.java:712)
                          at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3753)
                          at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4704)
                          at android.os.Handler.handleCallback(Handler.java:739)
                          at android.os.Handler.dispatchMessage(Handler.java:95)
                          at android.os.Looper.loop(Looper.java:148)
                          at android.app.ActivityThread.main(ActivityThread.java:7331)
                          at java.lang.reflect.Method.invoke(Native Method)
                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Amrmsmb
  • 1
  • 27
  • 104
  • 226

1 Answers1

0

you should not save the view in savedInstanceState. you should only save the value of the listview. it view will be created automatically

Noorul
  • 3,386
  • 3
  • 32
  • 54
  • I am not saving Views...i want to save a list of Views...each item in the list is a View – Amrmsmb Dec 19 '16 at 15:05
  • list of views means, view object right.? whatever, you should not do it. Views are heavy weight object. and when activity orientation changes, all views will be destroyed and recreated automatically. – Noorul Dec 19 '16 at 15:08
  • fine..is it ok to pass a list of Bitmaps? – Amrmsmb Dec 19 '16 at 15:14
  • 1
    yes. but you will face OutOfMemory error. because, each bitmap may have large in size. – Noorul Dec 19 '16 at 15:16