0

我只是将日志标签放在大多数活动和片段方法上,结果如下:

06-19 16:33:11.934: I/Fragment Activity:MainMenuPager(15820): onCreate - BEGIN
06-19 16:33:11.958: I/Fragment Activity:MainMenuPager(15820): onCreate - END
06-19 16:33:11.958: I/Fragment Activity:MainMenuPager(15820): onStart - BEGIN
06-19 16:33:11.958: I/Fragment Activity:MainMenuPager(15820): onStart - END
06-19 16:33:11.958: I/Fragment Activity:MainMenuPager(15820): onResume - BEGIN
06-19 16:33:11.958: I/Fragment Activity:MainMenuPager(15820): onResume - END
06-19 16:33:11.973: I/HomeFragment(15820): onAttach- BEGIN
06-19 16:33:11.973: I/HomeFragment(15820): onAttach- BEGIN
06-19 16:33:11.973: I/HomeFragment(15820): onCreate- BEGIN
06-19 16:33:11.973: I/HomeFragment(15820): onCreate- END
06-19 16:33:11.973: I/HomeFragment(15820): onCreateView- BEGIN
06-19 16:33:11.981: I/HomeFragment(15820): onCreateView- END
06-19 16:33:11.989: I/HomeFragment(15820): onActivityCreated- BEGIN
06-19 16:33:11.989: I/HomeFragment(15820): onActivityCreated- END
06-19 16:33:11.989: I/HomeFragment(15820): onStart- BEGIN
06-19 16:33:11.989: I/HomeFragment(15820): onStart- END
06-19 16:33:11.989: I/MyProcessListFragment(15820): onAttach- BEGIN
06-19 16:33:11.989: I/MyProcessListFragment(15820): onAttach- BEGIN
06-19 16:33:11.989: I/MyProcessListFragment(15820): onCreate- BEGIN
06-19 16:33:11.989: I/MyProcessListFragment(15820): onCreate- END
06-19 16:33:11.989: I/MyProcessListFragment(15820): onCreateView- BEGIN
06-19 16:33:12.012: I/MyProcessListFragment(15820): onCreateView- END
06-19 16:33:12.012: I/MyProcessListFragment(15820): onActivityCreated- BEGIN
06-19 16:33:12.012: I/MyProcessListFragment(15820): onActivityCreated- END
06-19 16:33:12.012: I/MyProcessListFragment(15820): onStart- BEGIN
06-19 16:33:12.012: I/MyProcessListFragment(15820): onStart- END

那么为什么所有记录的活动方法都首先运行,然后是所有 Fragment 的?片段应该在各种活动状态之间运行吗?

4

1 回答 1

1

抱歉,我在这里没有看到问题。首先,你有一个寻呼机,我们不知道你设置了适配器。您是否将其设置在 onResume 中?B/c 我猜这将与您的输出相匹配。

<fragment />如果您在布局中嵌入 a,您会看到什么样的输出?FragmentTransaction如果您通过onClick 侦听器中的 with-in添加片段,您会看到什么样的输出?这些都会有不同的日志记录结果,所以这里的问题更像是“猜猜我是如何编写代码”的游戏。

于 2012-06-20T15:50:29.087 回答