frankiesardo/icepick

Serialization into Map instead of Bundle

konmik opened this issue · 2 comments

Is it hard to create an Icepick variant that will put data into a map instead of Bundle? I'd like to use Icepick for parts of an application that do not have access to Android SDK.

I'm talking about MVP architecture, where Presenter is SDK-independent, so presenter's state could be saved into a Map and serialized by SDK-dependent code later.

This would allow to easily create code that can be tested without SDK/robolectric or used with https://github.com/google/j2objc.

It's not hard in principle, but it requires duplicating all the apis. Since Bundle is not an interface, that would make everything a lot harder to maintain.

I sympathize with your goal but in my experience abstracting these things from the SDK is a road filled with pain. For example, you won't catch bugs where you're passing things to the Map that cannot be properly Serialized into a Bundle.

If you don't want to execute Icepick logic during testing, remember that icepick.saveInstanceState and the like accept any Object, not just Activities and Fragment. I don't know the specifics of your MVP but you can extract the state logic in a separate object and mock it/stub it as needed. For example, Icepick works well with mortar Presenters.

Yeah, I know that it works perfectly with presenters! :)

OK, I'll probably try to fork it. I'll let you know how it goes, if you wish.

Thanks for Icepick, it is awesome! :)