toolargetool icon indicating copy to clipboard operation
toolargetool copied to clipboard

Why not save bundle in onCreate of Activity / Fragment?

Open zysidea opened this issue 5 years ago • 2 comments

Hi, I found that this tool check bundle only when onSaveInstanceState is called. But if put a big data in Bundle when open Activity or Fragment, it does not work.

zysidea avatar Nov 21 '20 07:11 zysidea

Hi @zysidea - You're right that the same exception can be thrown when calling startActivity or when adding a fragment if the intent extras or fragment args are too big. If I remember rightly, the problem for is that *TransactionTooLargeException is thrown before the onCreate callback so our activity/fragment state listeners don't get a change to log anything.

You can still use the functions in the library "manually" to check any bundles you suspect are causing problems e.g.

val myIntent = // your existing Intent creation code
TooLargeTool.logBundleBreakdown(tag = "CheckBigIntent", bundle = myIntent.extras)
startActivity(myIntent)

We could probably make that kind of usage easier and better documented than it is and possibly now we could even have Kotlin extension functions like this?

startActivityLoggingExtras(myIntent)

maxspencer avatar Jan 25 '21 16:01 maxspencer