-1

I'm trying to fix TransactionTooLarge exceptions. I can't find any main culprits in onSaveInstanceState.

However, when it comes to passing things to intents and bundles, I am seeing a lot of the follow type of code on a fragment.

companion object {

    fun newInstance(item1: Item1, item2: Item2): MyFragment {
        val fragment = MyFragment()
        val args = Bundle()
        args.putParcelableArrayList(ITEM_1_KEY, item1)
        args.putInt(ITEM_2_KEY, item2)
        fragment.arguments = args
        return fragment
    }
}

Essentially there's a bunch of code passing data models everywhere.

How do you get around trying to pass smaller objects in bundles to fragments?

These fragments basically just pick these up and use them. It feels difficult to avoid passing these through.

SmallGrammer
  • 893
  • 9
  • 19
  • Have you read the [Guide to app architecture](https://developer.android.com/jetpack/guide)? You should be fetching data from a repository layer, not sending it via arguments. – ianhanniballake Nov 29 '21 at 06:36
  • I've read the architecture guide. It's just the codebase I'm working on isn't architectured well. Essentially a lot of data is fetched from an API from a starting screen, then passed around to other fragments. It isn't stored or cached anywhere. So I was looking for simpler ways to get around this. – SmallGrammer Nov 29 '21 at 07:24
  • I've answered a similar question here: https://stackoverflow.com/a/73008611/2860701 . It may helps you. – Alberto Jul 17 '22 at 01:28

1 Answers1

0

Try to use middle man as ViewModel by viewModel you can attach same source of data between fragment and activity with the ability to update the data smoothly

Ahmed Karam
  • 386
  • 1
  • 7