livefront / bridge

An Android library for avoiding TransactionTooLargeException during state saving and restoration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mi device os version 7.1.2 issue

pals-ric opened this issue · comments

all the device i have tested my code with this library its working fine but mi one when i am switching my activity or i am going background again forground my previous activity data vanished .....
please anyone help me with this issue ... its happening only in mi os verion 7.1.2

What Bridge version are you using? Have you tried the latest (v1.1.3)? It might address whatever the issue is if the problem is with the "clear" method.

@pallavirichhariya22 Please let me know if you've reproduced this on the latest version. If I don't hear any follow-up information I'll probably just close this.

OK, I'm going to go ahead and close this ticket. Please feel free to re-open if the problems persist in the most recent version.

i have xiaomi note 4x and Bridge doesn't work i tried to store int and rotate the device and the value is not restored, but if i use icepick it works fine

@bagusxxalam Do you have some sample code with your setup? It's possible you don't have everything completely configured. For example, you need to call Bridge.initialize in your Application class.

Or have you confirmed Bridge works with other devices and just not that one?

i tested again now it works, but i still got toolargeexception
my app is using many fragments, the navigation is like instagram
so i tested opening 30+ fragments and when i minimize i got toolargeexception
TooLargeTool log

@bagusxxalam Are you properly using Bridge with your Fragments as well as your Activities? (See the discussion here). It simply shouldn't be possible to see TransactionTooLargeException using Bridge if everything is set up properly: there's nothing in the Bundles sent to the OS other than one UUID per Activity / Fragment, so you'd need thousands of Fragments to actually build up the Activity's save state enough to trigger another TransactionTooLargeException.

Can you describe how you are using Bridge with your Fragments?

i'm using this library for fragment navigation in my app https://github.com/ncapdevi/FragNav
to save the state based on the library i call below method on my MainActivity which host all of my fragments
fragNavController.onSaveInstanceState(myCustomBundleInMainActivity)
but it seems not because i call above method to cause the bundle sent to the os,
i try to comment that method still there's a still fragments that being sent to the os,

what i do is i store bundle myCustomBundleInMainActivity and save that as @State
currently i'm not calling bridge on my fragment, i'll try to call bridge on the fragment

i think it because my argument on the fragment i pass small object but if there's many fragments it add up to 500KB+, now i clear the fragment arguments when fragment initialization complete(at the end of onCreateView in my case)
and to provide the same argument when configuration changes i save the argument items using bridge
hopefully it can prevent the bundle reach 500KB

@bagusxxalam OK two things:

  1. You definitely need to make sure you are using Bridge for the saved state of your Fragments. Based on your logs and your recent comments, it appears you are not doing this. So you should absolutely do that first.
  2. If the problem is that the arguments for your Fragments are too big once you start adding up multiple of them, that's technically a separate problem that Bridge wasn't meant to solve. I'm considering adding functionality to Bridge at some point that allows you to avoid TransactionTooLargeException from large intent extras and Fragment arguments, though. See discussion on #19.

In the meantime, I can give you workaround if you believe the Fragment arguments are the problem. It looks like this:

  1. Make sure you are saving your Fragment saved state using Bridge if you are not already. This is key.
  2. Instead of placing data directly in your Fragment arguments, set them directly on the Fragment and save them with Bridge. For example, instead of
private LargeDataObject mLargeData;

public static YourFragment newInstance(@NonNull LargeDataObject largeData) {
    YourFragment fragment = new YourFragment();
    Bundle bundle = new Bundle();
    bundle.putParcelable("data", mLargeData);
    fragment.setArguments(bundle);
    return fragment;   
}

your can do this:

@State LargeDataObject mLargeData;

public static YourFragment newInstance(@NonNull LargeDataObject largeData) {
    YourFragment fragment = new YourFragment();
    fragment.mLargeData = largeData;
    return fragment;   
}

At first glance that will look like a terrible idea and seems to violate general principles of setting up Fragments. But it's actually safe because the data will always be saved to your saved state Bundle if you are in a situation where the Fragment would need to be destroyed and recreated. So until a Bridge update is made that allows you to put data of an arbitrary size into a Fragment's "arguments" (or just safely placing small amounts of data in many Fragments) I'd recommend something like this.

yes i think i will use that method by not passing bundle to the fragment but set the required param directly to the fragment, i try that yesterday and the size sent to the bundle decrease pretty much.
thank you @byencho