halfhp / androidplot

Charts and plots for Android
http://androidplot.com
Apache License 2.0
505 stars 159 forks source link

Storing series data in onSaveInstanceState broken #34

Closed phisi closed 7 years ago

phisi commented 7 years ago

This feature is broken and crashes the app (including the demo app). Try tapping out of the Zoom example. As far as I can see the bundle.putSerializable("seriesRegistry", plot.getRegistry()); call tries to serialize stuff that is not serializeable like Paint objects.

halfhp commented 7 years ago

I have not been able to replicate this in the TouchZoomExampleActivity in either the current release version of the DemoApp or in local builds of master. Can you provide the stack trace you're seeing?

phisi commented 7 years ago

I tested the issue again on API lvl 22 and 23 devices/emulator. To reproduce:

  1. Start DemoApp (tested with official build from playstore and current git master)
  2. Click TouchZoom Example
  3. Minimize App (calls onSaveInstanceState(Bundle bundle))

Stack trace:

03-16 08:43:11.973 3240-3240/com.androidplot.demos E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: com.androidplot.demos, PID: 3240
                                                                     java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.androidplot.xy.XYSeriesRegistry)
                                                                         at android.os.Parcel.writeSerializable(Parcel.java:1447)
                                                                         at android.os.Parcel.writeValue(Parcel.java:1395)
                                                                         at android.os.Parcel.writeArrayMapInternal(Parcel.java:665)
                                                                         at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
                                                                         at android.os.Bundle.writeToParcel(Bundle.java:1079)
                                                                         at android.os.Parcel.writeBundle(Parcel.java:690)
                                                                         at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3152)
                                                                         at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3417)
                                                                         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:5417)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                      Caused by: java.io.NotSerializableException: com.androidplot.xy.XYSeriesBundle
                                                                         at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
                                                                         at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
                                                                         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
                                                                         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
                                                                         at java.util.ArrayList.writeObject(ArrayList.java:648)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
                                                                         at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
                                                                         at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
                                                                         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
                                                                         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
                                                                         at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
                                                                         at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
                                                                         at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
                                                                         at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
                                                                         at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
                                                                         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
                                                                         at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
                                                                         at android.os.Parcel.writeSerializable(Parcel.java:1442)
                                                                         at android.os.Parcel.writeValue(Parcel.java:1395) 
                                                                         at android.os.Parcel.writeArrayMapInternal(Parcel.java:665) 
                                                                         at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330) 
                                                                         at android.os.Bundle.writeToParcel(Bundle.java:1079) 
                                                                         at android.os.Parcel.writeBundle(Parcel.java:690) 
                                                                         at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3152) 
                                                                         at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3417) 
                                                                         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:5417) 
                                                                         at java.lang.reflect.Method.invoke(Native Method) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
03-16 08:43:11.973 1639-1793/system_process W/ActivityManager:   Force finishing activity com.androidplot.demos/.TouchZoomExampleActivity
halfhp commented 7 years ago

thanks! im going to try to revisit this one over the weekend

halfhp commented 7 years ago

It's still unclear to me why it works on my phone but not on an emulator but I can verify the issue. Unfortunately I don't yet have a solution I'm happy with.

halfhp commented 7 years ago

At this point I've given up hope on finding an extensible way to serialize the entire SeriesRegistry. I'll be updating the example source and related documents to provide examples of serializing the series data only - formatters will unfortunately need to be created and configured from scratch on state change. It sucks but I don't see a workable alternative.

halfhp commented 7 years ago

Ugh. So even persisting a Series is problematic as a series with a size > 1mb in size will result in a TransactionTooLargeException

halfhp commented 7 years ago

changes merged in from PR #35.