【发布时间】:2016-11-08 15:14:19
【问题描述】:
根据docs
片段事务只能在 活动保存其状态。如果您尝试在之后提交事务 Activity.onSaveInstanceState() (以及在以下 Activity.onStart 或 Activity.onResume(),会报错。
我可以理解在Activity.onSaveInstanceState()之后片段事务不能提交的第一部分, 因为如果需要恢复活动,提交后的状态可能会丢失。
但我不明白为什么我们不能在 Activity.onStart 或 Activity.onResume() 之前提交片段事务? oncreate() 也是在Activity.onStart 或者Activity.onResume() 之前。是不是说我们在oncreate() 中都不能提交呢?
【问题讨论】:
标签: android android-fragments fragmenttransaction