【发布时间】:2021-04-26 09:13:56
【问题描述】:
在 Android documentation 中,我不太清楚通过 XML 添加片段与以编程方式添加片段相比有哪些优势和实际用例。
这两种方法都允许使用 Bundle 将数据从 Activity 发送到 Fragment 并返回吗?
这两种方法在活动生命周期中的行为是否相似?
一些简短的例子或参考肯定会有所帮助。
【问题讨论】:
-
advantages and practical use cases of adding fragments via XML如果可以在 xml 中定义片段,为什么还要编写样板代码来添加片段?Do both methods allow sending data from the activity to the fragment using Bundle?你可以自己试试。both methods behave similarly in the activity lifecycle?你也可以试试这个
标签: android android-layout android-fragments android-activity