我只是在大多数活动和片段方法上放置了日志标记,这就是结果:
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运行?如果片段1在各种活动状态之间运行???
答案 0 :(得分:1)
抱歉,我在这里看不到任何问题。首先,您有一个寻呼机,我们不知道您在某一时刻设置了适配器。你在onResume中设置它吗? B / c我猜这会与你的输出相匹配。
如果在布局中嵌入<fragment />
,您会看到什么样的输出?如果您通过FragmentTransaction
在onClick侦听器中添加片段,您会看到什么样的输出?这些都会有不同的日志记录结果,因此这里的问题更多的是“猜测我如何编写代码”的游戏。