What is "androidx.lifecycle.BundlableSavedStateRegistry.key" in this bundle?

2.2k Views Asked by At

I'm using toolargetool to investigate why the app is crashing from TransactionTooLargeException.

I'm seeing there's this key androidx.lifecycle.BundlableSavedStateRegistry.key which can be around 400 KB when I put the app into the background.

What is this key and where is it coming from? How can I reduce the size of this in the bundle?

1

There are 1 best solutions below

0
Mustafa Berkay Mutlu On

In my case, here are the things that was stored there:

  • androidx:appcompat = 0.1 KB
  • android:support:lifecycle = 0.1 KB
  • androidx.lifecycle.internal.SavedStateHandlesProvider = 1.2 KB
  • android:support:activity-result = 28.3 KB
  • android:support:fragments = 644.2 KB

I recommend you to debug this yourself because stored things and their sizes will be different for your project.

To debug:

  1. Put a breakpoint in TooLargeTool.bundleBreakdown() function. In the breakpoint, you can also use a filter like: KB(totalSize) > 500 so that it will stop at breakpoint only for the large sized Bundles such as Bundles that are larger than 500 KB.

breakpoint popup of TooLargeTool

  1. Once it hits the breakpoint you can "evaluate expression" in the IDE.

In the breakpoint try evaluating code like this:

val bundle: Bundle = bundle.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key")!!
// bundleBreakdown(bundle) // <- this gives you a report including size etc.
val fragmentsBundle = bundle.getBundle("android:support:fragments")!!
bundleBreakdown(fragmentsBundle)

You can of course also see the bundles in the IDE's Debug window, but it will be difficult to see the Bundle keys and sizes.

This way you can find out exactly what takes up space in this Bundle with key androidx.lifecycle.BundlableSavedStateRegistry.key