Scrounger / CountryCurrencyPicker

CountryCurrencyPicker is an android picker library for country and / or currency. You can implement it as fragment or dialog. It offers the option to search for country values and / or currency values. Inspired by country-picker-android and currency-picker-android
Apache License 2.0
36 stars 11 forks source link

Crashes when app goes to background #2

Open pouriabagheri opened 6 years ago

pouriabagheri commented 6 years ago

@Scrounger the app crashes when it goes to background by pressing home button. seems to be an issue due to serialization Here is the log:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.scrounger.countrycurrencypicker.sample, PID: 9449 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.scrounger.countrycurrencypicker.library.Buttons.CountryCurrencyButton) at android.os.Parcel.writeSerializable(Parcel.java:1761) at android.os.Parcel.writeValue(Parcel.java:1709) at android.os.Parcel.writeArrayMapInternal(Parcel.java:777) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506) at android.os.Bundle.writeToParcel(Bundle.java:1181) at android.os.Parcel.writeBundle(Parcel.java:817) at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:148) at android.os.Parcel.writeTypedArray(Parcel.java:1401) at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:571) at android.os.Parcel.writeParcelable(Parcel.java:1730) at android.os.Parcel.writeValue(Parcel.java:1636) at android.os.Parcel.writeArrayMapInternal(Parcel.java:777) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506) at android.os.Bundle.writeToParcel(Bundle.java:1181) at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:4617) at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4012) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:172) at android.app.ActivityThread.main(ActivityThread.java:6637) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.io.NotSerializableException: com.scrounger.countrycurrencypicker.library.Country at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1233) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1597) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1558) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1481) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1227) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) at android.os.Parcel.writeSerializable(Parcel.java:1756) at android.os.Parcel.writeValue(Parcel.java:1709)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:777)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)  at android.os.Bundle.writeToParcel(Bundle.java:1181)  at android.os.Parcel.writeBundle(Parcel.java:817)  at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:148)  at android.os.Parcel.writeTypedArray(Parcel.java:1401)  at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:571)  at android.os.Parcel.writeParcelable(Parcel.java:1730)  at android.os.Parcel.writeValue(Parcel.java:1636)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:777)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)  at android.os.Bundle.writeToParcel(Bundle.java:1181)  at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:4617)  at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4012)  at android.os.Handler.handleCallback(Handler.java:789)  at android.os.Handler.dispatchMessage(Handler.java:98)  at android.os.Looper.loop(Looper.java:172)  at android.app.ActivityThread.main(ActivityThread.java:6637)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

pouriabagheri commented 6 years ago

For those who face this issue, the cause is serializing listener. so when state loss occurs serialization recreates the listener object ( using the values in the object not the reference ) so the new listener is just a copy of the listener object. the solution is to remove the serialization from listener and create the listeners directly and calling them through the picker object.