livefront / bridge

An Android library for avoiding TransactionTooLargeException during state saving and restoration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't work for multiple instances

RuiRoque-FA opened this issue · comments

For example, if we have a Fragment used in an adapter in which for every adapter position a new instance of that fragment is created, we cannot use Bridge in that Fragment.

On the first onDestroy event of any of the instances, all the instance state of every fragment is deleted. Also, every time we save the instance state of one of the fragments, the fragment's state of the previous view is lost. I think it's because you use "target.getClass().getName()" for identifying the target object.

Or, I can be wrong and doing something wrong.

I'm pretty sure this is related to an overly aggressive optimization I added that clears saved data for any object that goes out of memory (which is fine in most standard cases but appears to cause problems in others). This is the same issue discussed in #11 . I'm planning on tweaking this in a future release. For now, see if a change like this one fixes your issue : https://github.com/enjoei/bridge/pull/1/files#diff-fdeed58223e4d4fb778400989ef3dc82L201

You also might need to try removing any Bridge.clear(this) calls from these particular Fragments. If those two tweaks don't help I'll investigate further.

@RuiRoque-FA In the v1.1.2 release I've removed the automatic data clearing that I've mentioned. Please check that updating to this version and removing the Bridge.clear() calls in those particular Fragment classes fixes your issue. Also note that I've created an issue (#17) to track future changes that will allow the clearing of data to be deferred until a later point.

@RuiRoque-FA I'm going to close this issue for now. If you follow the instructions above and still see the problem, please reopen this issue.