2

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?

SmallGrammer
  • 893
  • 9
  • 19
  • That key is itself a `Bundle`. What inside _that_ Bundle is actually taking up space? – ianhanniballake Jun 28 '22 at 05:04
  • After some investigation, I think the key is relating to some values stored via `SavedStateHandle` in the view model. I found out some huge data being passed through there. Not sure why `TooLargeTool` doesn't give me the key values defined in the VM and passed through `SavedStateHandle` instead of giving me `androidx.lifecycle.BundlableSavedStateRegistry.key`. I could be wrong on this assumption though. – SmallGrammer Jun 28 '22 at 07:02
  • I've answered a similar question here: https://stackoverflow.com/a/73008611/2860701 – Alberto Jul 18 '22 at 16:29
  • i have the same question: [enter link description here](https://stackoverflow.com/questions/76548713/about-activity-onsaveinstancestate-toolarge-the-question-cause-by-androidx-lif) – Len Jun 25 '23 at 03:31

1 Answers1

5

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

Mustafa Berkay Mutlu
  • 1,929
  • 1
  • 25
  • 37