Fragment生命周期

  • Fragement生命周期

image

a、正常情况下

  • 进入A页面
    Activity:      onCreate()
    Fragment:      onAttach()
    Fragment:      onCreate()
    Fragment:      onCreateView()
    Fragment:      onActivityCreated()
    Activity:      onStart()
    Fragment:      onStart()
    Activity:      onResume()
    Fragment:      onResume()
    
  • A页面 →→ B页面
     Activity:      onPause()
     Fragment:      onStop()
     Activity:      onStop()
    
  • B页面 →→ A 页面
      Activity:      onRestart()
      Activity:      onStart()
      Fragment:      onStart()
      Activity:      onResume()
      Fragment:      onResume()
    

b、横竖屏切换

  • 正常进入
      Activity:      onCreate()
      Fragment:      onAttach()
      Fragment:      onCreate()
      Fragment:      onCreateView()
      Fragment:      onActivityCreated()
      Activity:      onStart()
      Fragment:      onStart()
      Activity:      onResume()
      Fragment:      onResume()
    
  • 横竖屏切换
      Activity:     onPause()
      Fragment:     onStop()
      Activity:     onStop()
      Fragment:     onDestroyView()
      Fragment:     onDetach()
      Activity:     onDestroy()
      Fragment:     onAttach()
      Fragment:     onCreate()
      Activity:     onCreate()
      Fragment:     onCreateView()
      Fragment:     onActivityCreated()
      Fragment:     onAttach()
      Fragment:     onCreate()
      Fragment:     onDestroyView()
      Fragment:     onDetach()
      Fragment:     onCreateView()
      Fragment:     onActivityCreated()
      Activity:     onStart()
      Fragment:     onStart()
      Activity:     onResume()
      Fragment:     onResume()
    

c、前后台切换

  • 正常进入
      Activity:      onCreate()
      Fragment:      onAttach()
      Fragment:      onCreate()
      Fragment:      onCreateView()
      Fragment:      onActivityCreated()
      Activity:      onStart()
      Fragment:      onStart()
      Activity:      onResume()
      Fragment:      onResume()
    
  • 切换至后台
    Activity:    onPause()
    Fragment:    onStop()
    Activity:    onStop()
    
  • 切换至前台
    Activity:    onRestart()
    Activity:    onStart()
    Fragment:    onStart()
    Activity:    onResume()
    Fragment:    onResume()

你可能感兴趣的:(Fragment生命周期)