livefront / bridge

An Android library for avoiding TransactionTooLargeException during state saving and restoration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not solve TransactionTooLargeException with icepick library

yogeshchoudhary147 opened this issue · comments

Hi @byencho ,

When used with icepick library, the TransactionTooLargeException still occurs.

Sample Code:

MyActivity.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bridge.restoreInstanceState(this, savedInstanceState);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Bridge.saveInstanceState(this, outState);
}

@Override
public void onDestroy() {
    super.onDestroy();
    Bridge.clear(this);
}

MyApplication.java:

import icepick.Icepick;
import com.livefront.bridge.Bridge;
import com.livefront.bridge.SavedStateHandler;

@Override
public void onCreate() {
    super.onCreate();
    Bridge.initialize(getApplicationContext(), new SavedStateHandler() {
        @Override
        public void restoreInstanceState(@NonNull Object target, @Nullable Bundle state) {
            Icepick.restoreInstanceState(target, state);
        }
        @Override
        public void saveInstanceState(@NonNull Object target, @NonNull Bundle state) {
            Icepick.saveInstanceState(target, state);
        }
    });
}

It is a react native app with single activity.

dependencies {
    compile 'com.github.livefront:bridge:v1.1.3'
    compile 'frankiesardo:icepick:3.2.0'
    annotationProcessor 'frankiesardo:icepick-processor:3.2.0'
}


@yogeshchoudhary147 You'd need to show me how you are saving your data. If you're not using @State annotations (which is how Icepick works), you're not going to avoid the problem.

Thanks for your quick response @byencho.

I am not actually not doing anything else in MainActivity.java. I am not using @State annotations. I recently upgraded my app's targetSdkVersion and this crash started happening. That's when I came across your library. Please guide me what needs to be done to get rid of this crash.

@yogeshchoudhary147 If you are not using @State, then using Bridge + Icepick does nothing. Please refer to the Icepick docs or check out the Bridge sample app for appropriate usage.

If you are not manually saving any other kind of state in your Activity, then the problem is probably too much state being saved in the Views by React Native. Please see the (unresolved) issue discussion here : facebook/react-native#19458 .

@yogeshchoudhary147 I'm going to close this issue for now, since it's really just a problem with state-saving inside React-Native and not with Bridge / Icepick. Bridge is only intended to help with state you manually save yourself inside an Activity / Fragment / etc., not in state that is saved generically by the OS or some third-party library.