简体   繁体   English

如何绕过将数据模型传递给 arguments 以避免事务太大异常?

[英]How to get around passing data models to fragment arguments to avoid Transaction Too Large Exception?

I'm trying to fix TransactionTooLarge exceptions.我正在尝试修复TransactionTooLarge异常。 I can't find any main culprits in onSaveInstanceState .我在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.感觉很难避免通过这些。

Convert Data Models to JSON and pass it or store it as String.将数据模型转换为 JSON 并将其传递或存储为字符串。 I had faced a similar kind of issue, I had implemented the same way我遇到过类似的问题,我以同样的方式实施

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尝试通过 viewModel 使用中间人作为 ViewModel,您可以在片段和活动之间附加相同的数据源,并能够顺利更新数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CropImageView事务太大异常 - CropImageView Transaction too large Exception 带有 rememberLauncherForActivityResult 的事务太大异常 - Transaction Too Large Exception with rememberLauncherForActivityResult 如何避免使用MVP方法在方法中传递大量参数 - How to avoid passing large number of arguments in method using MVP approach 当我将数据传递到第三片段时出现异常,但是将数据传递到第二片段可以正常工作 - I get exception when i pass data to third fragment but it works ok for passing data to the second fragment 将数据从活动传递到片段空指针异常 - Passing data from activity to fragment nullpointer exception 将数据从活动传递到片段 transaction.replace() - Passing data from activity to fragment transaction.replace() 将参数束传递给Fragment - Passing arguments bundle to Fragment 空指针异常,用于将数据从一个片段传递到另一个片段 - Null pointer exception for passing data from one fragment to another fragment 如何避免每次进行零散交易时布局膨胀? - How to avoid the layout inflation each time a fragment transaction is committed? 为什么在将数据从活动传递到片段时出现空指针异常? - Why do I get a null pointer exception while passing the data from activity to fragment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM