onSavedInstanceState TransactionTooLargeException (only on lock screen or start activity not on rotate screen)

1k Views Asked by At

I'm facing an issue on the Activity Lifecycle when onSavedInstanceState is Called.

Let me explain : I have 4 Fragments on ViewPager hosting RecyclerViews. These RecyclerViews display data from HashMap<String, AMedia>().

The HashMap can be large, when I rotate the phone (portrait/landscape) the onSavedInstanceState and on onViewStateRestored are called and data are well transmitted by the Framework on the UI like following :

@Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putSerializable("medias", mMapMedias);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
        super.onViewStateRestored(savedInstanceState);
        if (savedInstanceState != null) {
            mMapMedias = (HashMap<String, ArrayList<AMedia>>) savedInstanceState.getSerializable("medias");
            render();
        }
    }

But when I lock or start an other activity the phone only onSaveInstanceState and app begins crash on the lock screen with error :

JNI critical lock held for 29.211ms on Thread[1,tid=27712,Runnable,Thread*=0xb400007388322010,peer=0x73356338,"main"]
JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 45037652)
W/ActivityStopInfo: Bundle stats:
ActivityStopInfo:   android:viewHierarchyState [size=1036]
JNI critical lock held for 128.524ms on Thread[1,tid=27712,Runnable,Thread*=0xb400007388322010,peer=0x73356338,"main"]
ActivityStopInfo:   androidx.lifecycle.BundlableSavedStateRegistry.key [size=45035172]
ActivityStopInfo:     android:support:activity-result [size=2908]
ActivityStopInfo:       KEY_COMPONENT_ACTIVITY_REGISTERED_KEYS [size=2192]
JNI critical lock held for 88.565ms on Thread[1,tid=27712,Runnable,Thread*=0xb400007388322010,peer=0x73356338,"main"]
ActivityStopInfo:     android:support:fragments [size=45032008]
JNI critical lock held for 86.960ms on Thread[1,tid=27712,Runnable,Thread*=0xb400007388322010,peer=0x73356338,"main"]
ActivityStopInfo:       android:support:fragments [size=45031936]
ActivityStopInfo: PersistableBundle stats:
W/ActivityStopInfo:   [null]
AndroidRuntime: Shutting down VM
    
    --------- beginning of crash
AndroidRuntime: FATAL EXCEPTION: main
    PID: 27712
    java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 45037652 bytes
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:161)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8010)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
     Caused by: android.os.TransactionTooLargeException: data parcel size 45037652 bytes
        at android.os.BinderProxy.transactNative(Native Method)
        at android.os.BinderProxy.transact(BinderProxy.java:591)
        at android.app.IActivityTaskManager$Stub$Proxy.activityStopped(IActivityTaskManager.java:4408)
        at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:145)

I think on rotate the same calls are done through JavaBinder but not crashing, why on Lock or start an other activity it crashs ?

Any solution ? I'm testing on Android 12.

0

There are 0 best solutions below