Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday 2 November 2019

Fragment Lifecycle Communication

    This is the most important question for interview point of view.


Case 1:  When not use "addToBackStack()" and use "add" method


      MainActivity : onCreate()

      A_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart()

      

      MainActivity : onStart() -- onResume()

      A_Fragment: onResume()
     
      Click the Next button to navigate to B_Fragment

      B_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart() --                                onResume()

      
       Click the Next button to navigate to C_Fragment



      C_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart() --                                onResume()

        Back button click

      A_Fragment: onPause()
      B_Fragment: onPause()
      C_Fragment: onPause()

      MainActivity : onPause()
      
      A_Fragment: onStop()
      B_Fragment: onStop()

      C_Fragment: onStop()

     MainActivity : onStop()

      A_Fragment: onDestroyView()
      A_Fragment: onDestroy()


      A_Fragment: onDettach()

      B_Fragment: onDestroyView()
      B_Fragment: onDestroy()



      B_Fragment: onDettach()

      C_Fragment: onDestroyView()
      C_Fragment: onDestroy()



      C_Fragment: onDettach()

      MainActivity : onDestroy()



Case 2:  When use "addToBackStack()" and use "add" method



      MainActivity : onCreate()

      A_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart()

      

      MainActivity : onStart() -- onResume()

      A_Fragment: onResume()
      

      Click the Next button to navigate to B_Fragment

      B_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart() --                                onResume()

      
       Click the Next button to navigate to C_Fragment



      C_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart() --                                onResume()

        Back button click

      C_Fragment: onPause()
      C_Fragment: onStop()
      C_Fragment: onDestroyView()
      C_Fragment: onDestroy()
      C_Fragment: onDettach()  

      Again Back button click

     
      B_FragmentonPause()
      B_FragmentonStop()
      B_FragmentonDestroyView()
      B_FragmentonDestroy()
      B_FragmentonDettach()

     Again  Back button click

     
      A_FragmentonPause()
      A_FragmentonStop()
      A_FragmentonDestroyView()
      A_FragmentonDestroy()
      A_FragmentonDettach()  
  
     Again Back button click


    MainActivity : onPause() -- onStop() -- onDestroy()



Case 2:  When use "addToBackStack()" and use "add"  and "replace"method



      MainActivity : onCreate()

      A_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart()

      

      MainActivity : onStart() -- onResume()

      A_Fragment: onResume()
     

      Click the Next button to navigate to B_Fragment

      B_Fragment : onAttach() -- onCreate() -- onCreateView() -- onViewCreated() --     onActivityCreated() -- onStart() --  onResume()

      
       Click the Next button to navigate B to C_Fragment using "replace" method



      C_Fragment : onAttach() --onCreate() 

      B_Fragment : onPause() -- onStop() -- onDestroyView() 

      A_Fragment : onPause() -- onStop() -- onDestroyView() 

      C_Fragment : onCreateView() -- onActivityCreated() -- onStart() --  onResume()

        Back button click

      C_Fragment: onPause()
      C_Fragment: onStop()
      C_Fragment: onDestroyView()
      C_Fragment: onDestroy()
      C_Fragment: onDettach()  

      A_Fragment: onCreateView()
      A_Fragment: onViewCreated()
      A_Fragment: onActivityCreated()
      A_Fragment: onStart()

      A_FragmentonResume()  

      B_FragmentonCreateView()
      B_FragmentonViewCreated()
      B_FragmentonActivityCreated()
      B_FragmentonStart()


      B_FragmentonResume()  


      Again Back button click

      B_FragmentonPause()
      B_FragmentonStop()
      B_FragmentonDestroyView()
      B_FragmentonDestroy()

      B_FragmentonDettach() 

     Again Back button click

      A_FragmentonPause()
      A_FragmentonStop()
      A_FragmentonDestroyView()
      A_FragmentonDestroy()


      A_FragmentonDettach() 

      Again Back button click


       MainActivity : onPause() -- onStop() -- onDestroy()





Case 3:  When not use "addToBackStack()" and use "replace"method




      MainActivity : onCreate()

      A_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart()

      

      MainActivity : onStart() -- onResume()

      A_Fragment: onResume()
     

      Click the Next button to navigate A_Fragment to B_Fragment


      B_Fragment : onAttach() -- onCreate() 
      A_Fragment : onPause() -- onStop() -- onDestroyView() -- onDestroy() 
      B_Fragment : onCreateView() -- onActivityCreated() -- onStart() -- onResume()


      

     Click the Next button to navigate B_Fragment to C_Fragment



      C_Fragment : onAttach() -- onCreate() 
      B_Fragment : onPause() -- onStop() -- onDestroyView() -- onDestroy() 
      C_Fragment : onCreateView() -- onActivityCreated() -- onStart() -- onResume()


      
        Back button click

       C_Fragment : onPause() 
       MainActivity : onPause()
       C_Fragment : onStop() 
       MainActivity : onStop()
       C_Fragment : onDestroyView() -- onDestroy() --  onDettach() 
        MainActivity : onDestroy()


     Case 3:  When use "addToBackStack()" and use "replace"method



      MainActivity : onCreate()

      A_Fragment : onAttach() -- onCreate() -- onCreateView() -- onActivityCreated() -- onStart()

      

      MainActivity : onStart() -- onResume()

      A_Fragment: onResume()
     

      Click the Next button to navigate A_Fragment to B_Fragment


      B_Fragment : onAttach() -- onCreate() 
      A_Fragment : onPause() -- onStop() -- onDestroyView() 
      B_Fragment : onCreateView() -- onActivityCreated() -- onStart() -- onResume()


      

     Click the Next button to navigate B_Fragment to C_Fragment



      C_Fragment : onAttach() -- onCreate() 
      B_Fragment : onPause() -- onStop() -- onDestroyView() 
      C_Fragment : onCreateView() -- onActivityCreated() -- onStart() -- onResume()


      
        Back button click

      C_FragmentonPause()
      C_FragmentonStop()
      C_FragmentonDestroyView()
      C_FragmentonDestroy()


      C_FragmentonDettach() 

      B_Fragment : onCreateView() -- onActivityCreated() -- onStart() -- onResume()


       
       Back button click

      B_FragmentonPause()
      B_FragmentonStop()
      B_FragmentonDestroyView()
      B_FragmentonDestroy()


      B_FragmentonDettach() 

      A_Fragment : onCreateView() -- onActivityCreated() -- onStart() -- onResume()



       
      Back button click



       MainActivity : onPause() -- onStop() -- onDestroy()




      Thanks



No comments:

Post a Comment