首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TransactionTooLargeException on ViewPager2

TransactionTooLargeException on ViewPager2
EN

Stack Overflow用户
提问于 2021-05-14 19:30:45
回答 1查看 851关注 0票数 2

我见过很多关于ViewPager的问题,但现在是在ViewPager2上。

我得到了java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel和ViewPager2。我已经看到TooLargeTool可以帮助确定这个TooLargeException从何而来。我的捆绑包是bestof_date,相当低(0.1KB),但是android:support:fragments却一直在增加

所有这些都来自使用ViewPager + FragmentStateAdapter的标准实现,因为我可以有一个150+选项卡。

代码语言:javascript
运行
复制
2021-05-14 17:08:16.373 com.my.application D/TooLargeTool: MainActivity.onSaveInstanceState wrote: Bundle167873131 contains 10 keys and measures 43.7 KB when serialized as a Parcel
    * com.google.app_measurement.screen_service = 0.2 KB
    * KEY_COMPONENT_ACTIVITY_RANDOM_OBJECT = 0.2 KB
    * android:viewHierarchyState = 1.9 KB
    * KEY_COMPONENT_ACTIVITY_REGISTERED_KEYS = 9.8 KB
    * androidx.lifecycle.BundlableSavedStateRegistry.key = 30.3 KB
    * KEY_COMPONENT_ACTIVITY_REGISTERED_RCS = 0.6 KB
    * KEY_COMPONENT_ACTIVITY_PENDING_RESULT = 0.1 KB
    * KEY_COMPONENT_ACTIVITY_LAUNCHED_KEYS = 0.1 KB
    * android:lastAutofillId = 0.1 KB
    * android:fragments = 0.4 KB
2021-05-14 17:08:16.482 com.my.application D/TooLargeTool: BestofVideosFragment.onSaveInstanceState wrote: Bundle168360416 contains 3 keys and measures 1.2 KB when serialized as a Parcel
    * androidx.lifecycle.BundlableSavedStateRegistry.key = 0.1 KB
    * android:view_registry_state = 0.2 KB
    * android:view_state = 0.9 KB
    * fragment arguments = Bundle87348377 contains 1 keys and measures 0.1 KB when serialized as a Parcel
    * bestof_date = 0.1 KB
2021-05-14 17:08:17.003 com.my.application D/TooLargeTool: BestofFragment.onSaveInstanceState wrote: Bundle113147201 contains 4 keys and measures 24.0 KB when serialized as a Parcel
    * android:support:fragments = 22.5 KB
    * androidx.lifecycle.BundlableSavedStateRegistry.key = 0.1 KB
    * android:view_registry_state = 0.2 KB
    * android:view_state = 1.2 KB
    * fragment arguments = Bundle176902886 contains 0 keys and measures 0.0 KB when serialized as a Parcel
2021-05-14 17:08:17.075 com.my.application D/TooLargeTool: NavHostFragment.onSaveInstanceState wrote: Bundle75010087 contains 7 keys and measures 29.1 KB when serialized as a Parcel
    * android:support:fragments = 26.9 KB
    * androidx.lifecycle.BundlableSavedStateRegistry.key = 0.1 KB
    * android-support-nav:fragment:defaultHost = 0.1 KB
    * android:view_registry_state = 0.2 KB
    * android-support-nav:fragment:graphId = 0.1 KB
    * android-support-nav:fragment:navControllerState = 1.5 KB
    * android:view_state = 0.1 KB

更新1:经过更多的搜索后,我发现是因为FragmentStateAdapter保存了堆积的视图状态,直到我们达到最大容量和崩溃为止,有什么方法可以清除这个问题吗?

EN

Stack Overflow用户

发布于 2021-08-03 08:53:15

结果,我强迫navController保存用户访问的每个屏幕,因此创建了一个大的后台。

代码语言:javascript
运行
复制
bottomNavigation?.setOnItemSelectedListener {
    navController.navigate(it.itemId)
    true
}

我之所以使用这个片段,是因为我的一个项目在底部栏中有一个bottomSheetDialog,当单击它时,导航会将我送回startDestination。

我换了https://developer.android.com/reference/androidx/navigation/ui/NavigationUI#onnavdestinationselected

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:title="@string/title_home"
        android:id="@id/homeFragment"
        android:icon="@drawable/ic_home"/>

    <item android:title="@string/title_more"
        android:id="@id/plusFragment"
        android:icon="@drawable/ic_plus"              
        android:menuCategory="secondary" />
</menu>
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67540003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档