livefront / bridge

An Android library for avoiding TransactionTooLargeException during state saving and restoration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Usage of IceKick

JEuler opened this issue · comments

Sorry, maybe this is a newbish question and maybe it is not about your library at all, but I don't understand how to use Bridge with Icekick you mentioned. Icekick provides only the extensions for View, Activity, Fragment. And I cannot setup it globally in Application class

Bridge.initialize(applicationContext, object : SavedStateHandler {
            override fun restoreInstanceState(@NonNull target: Any, @NonNull state: Bundle?) {
// what to write here?
            }

            override fun saveInstanceState(@NonNull target: Any, @NonNull state: Bundle) {
// what to write here?
            }
        })

I am just trying to use library without EPL license.

So I haven't explicitly tried using Icekick myself but based on their docs I'd imagine it would look like this:

Bridge.initialize(applicationContext, object : SavedStateHandler {
        override fun restoreInstanceState(target: Any, state: Bundle?) {
            IceKick.unfreezeInstanceState(target, state)
        }

        override fun saveInstanceState(target: Any, state: Bundle) {
            IceKick.freezeInstanceState(target, state)
        }
})

You'd still need to use by parcelState(), by serialState(), etc. manually in each class to save those properties.

@JEuler OK now I'm finally seeing that the global IceKick.unfreezeInstanceState and IceKick.freezeInstanceState are internal. Yeah so then I'm not 100% sure what to do in these cases. You might try:

Bridge.initialize(applicationContext, object : SavedStateHandler {
        override fun restoreInstanceState(target: Any, state: Bundle?) {
               when (target) {
                   is Activity -> target.unfreezeInstanceState(target, state)
                   is Fragment -> target.unfreezeInstanceState(target, state)
               }
        }

        override fun saveInstanceState(target: Any, state: Bundle) {
               when (target) {
                   is Activity -> target.freezeInstanceState(target, state)
                   is Fragment -> target.freezeInstanceState(target, state)
               }
        }
})

but that's only going to get you so far. That seems like a really odd limitation on the part of IceKick. In any case, you could try that, or you could try the Android-State / StateSaver library. That's compatible with Kotlin and uses annotations and is what I'd personally recommend in general.

Thank you very much, yeah, they are internal. I think your code will work just fine. Will try it in project.

Regarding Andriod-State... It is nice, but it is EPL. Maybe you can answer me if it is safe to use EPL licensed libraries for the commercial project distributed by binaries?

Ah, I see. So I would think you'd be fine to use EPL in a commercial project, since I know several that do. That being said, I'm not a lawyer so that sort of thing is not 100% clear to me. It might depend on the project. I know I've been on projects where only MIT and Apache are allowed, for example. So I can't really answer that question for you, unfortunately.

Thank you very much for the discussion. Yeah, I also think that all is okay. But, need to be sure. I asked in AndroidState repository about license, waiting for answer. Meanwhile I will try the

 when (target) {
                   is Activity -> target.unfreezeInstanceState(target, state)
                   is Fragment -> target.unfreezeInstanceState(target, state)
               }

code. Thanks!

I've tried it and it worked! Thank you!

Cool, glad I could help! I'm going to go ahead and close this issue at this point. Let me know if you have any more questions.