Closed Trikke closed 9 years ago
I don't think that is allowed to happen. View
does not implement Serializable
or Parcelable
, so compilation would fail with something like Don't know how to put YourCustomView into a Bundle
.
Can you confirm that this is indeed the resulting behaviour?
Ah, indeed. I never thought of the fact that all objects that are ice-picked (if that even is a verb) should implement Serializable or Parcable. I never tried to compile that code since I immediately saw my error. And it would be bad practice to even create a custom view which would implement either interface, so i think this case is covered. I might have acted too fast..
While i was implementing Icepick, i copy-pasted a bit too fast and almost tried to save a view in the saved state bundle. So i thought it'd be a cool idea if Icepick would throw a warning that you are trying to save certain types of context related classes in the bundle.
The easiest way i could think of, is just to have a blacklist of such classes. Anything that extends a View, Activity, Fragment, Application, Context, and so on. I don't know the inner workings of annotation processing, but one could maybe also check if the object being saved has a field of the type Context. So even custom classes would trigger a warning.